-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathai-chat.sh
More file actions
executable file
·68 lines (61 loc) · 1.94 KB
/
ai-chat.sh
File metadata and controls
executable file
·68 lines (61 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
# 简单的AI聊天脚本
API_URL="http://localhost:8080/api/v1/chat/text"
# 如果没有参数,显示帮助
if [ $# -eq 0 ]; then
echo "使用方法:"
echo " $0 \"你的问题\" # 提问一个问题"
echo " $0 -i # 交互模式"
echo " $0 -s # 检查API状态"
echo " $0 -h # 显示帮助"
exit 0
fi
case "$1" in
-i|--interactive)
echo "🤖 AI聊天交互模式 (输入'退出'结束)"
echo "================================="
while true; do
echo -n "你: "
read question
if [ "$question" = "退出" ] || [ "$question" = "exit" ]; then
echo "再见!"
break
fi
echo -n "AI: "
curl -s -X POST "$API_URL" \
-H "Content-Type: application/json" \
-d "{\"message\": \"$question\"}"
echo ""
done
;;
-s|--status)
echo "🔍 检查API状态..."
curl -s http://localhost:8080/api/v1/status | python3 -c "
import json, sys
data = json.load(sys.stdin)
print('✅ 服务:', data['service'])
print('📊 状态:', data['status'])
print('🤖 模型:', data['model'])
print('🔑 API配置:', data['api_configured'])
print('🌐 基础URL:', data['base_url'])
"
;;
-h|--help)
echo "AI聊天客户端"
echo "命令:"
echo " -i, --interactive 交互模式"
echo " -s, --status 检查API状态"
echo " -h, --help 显示帮助"
echo " 其他任何文本 提问问题"
;;
*)
# 直接提问
question="$*"
echo "提问: $question"
echo -n "回答: "
curl -s -X POST "$API_URL" \
-H "Content-Type: application/json" \
-d "{\"message\": \"$question\"}"
echo ""
;;
esac