1+ # PowerShell AI聊天API测试脚本 - 无乱码版本
2+
3+ Write-Host " 🤖 AI聊天API测试" - ForegroundColor Cyan
4+ Write-Host " =================" - ForegroundColor Cyan
5+
6+ # 测试纯文本端点
7+ Write-Host " `n 1. 测试纯文本端点 (推荐)" - ForegroundColor Green
8+ $questions = @ (
9+ " 你好,请用中文介绍一下你自己" ,
10+ " 今天天气怎么样?" ,
11+ " 讲一个简短的笑话" ,
12+ " 用一句话说明什么是人工智能"
13+ )
14+
15+ foreach ($q in $questions ) {
16+ Write-Host " `n 提问: $q " - ForegroundColor Yellow
17+ $body = @ {message = $q } | ConvertTo-Json
18+ try {
19+ $response = Invoke-RestMethod - Uri " http://localhost:8080/api/v1/chat/text" - Method Post - Body $body - ContentType " application/json" - ErrorAction Stop
20+ Write-Host " 回答: $response " - ForegroundColor White
21+ } catch {
22+ Write-Host " 错误: $_ " - ForegroundColor Red
23+ }
24+ Start-Sleep - Milliseconds 500
25+ }
26+
27+ # 测试状态检查
28+ Write-Host " `n 2. 测试API状态" - ForegroundColor Green
29+ try {
30+ $status = Invoke-RestMethod - Uri " http://localhost:8080/api/v1/status" - Method Get - ErrorAction Stop
31+ Write-Host " ✅ API状态正常" - ForegroundColor Green
32+ Write-Host " 服务: $ ( $status.service ) " - ForegroundColor White
33+ Write-Host " 状态: $ ( $status.status ) " - ForegroundColor White
34+ Write-Host " 模型: $ ( $status.model ) " - ForegroundColor White
35+ Write-Host " API配置: $ ( $status.api_configured ) " - ForegroundColor White
36+ } catch {
37+ Write-Host " ❌ 状态检查失败: $_ " - ForegroundColor Red
38+ }
39+
40+ # 交互模式
41+ Write-Host " `n 3. 交互模式 (输入'退出'结束)" - ForegroundColor Green
42+ while ($true ) {
43+ $userInput = Read-Host " `n 你的问题"
44+ if ($userInput -eq " 退出" -or $userInput -eq " exit" ) {
45+ break
46+ }
47+
48+ $body = @ {message = $userInput } | ConvertTo-Json
49+ try {
50+ $response = Invoke-RestMethod - Uri " http://localhost:8080/api/v1/chat/text" - Method Post - Body $body - ContentType " application/json" - ErrorAction Stop
51+ Write-Host " `n 🤖 AI: $response " - ForegroundColor Cyan
52+ } catch {
53+ Write-Host " 错误: $_ " - ForegroundColor Red
54+ }
55+ }
56+
57+ Write-Host " `n ✅ 测试完成" - ForegroundColor Green
58+ Write-Host " `n 📋 快速命令参考:" - ForegroundColor Yellow
59+ Write-Host " # 一句话测试" - ForegroundColor Gray
60+ Write-Host " Invoke-RestMethod -Uri 'http://localhost:8080/api/v1/chat/text' -Method Post -Body (@{message='你好'} | ConvertTo-Json) -ContentType 'application/json'" - ForegroundColor White
61+ Write-Host " `n # 使用curl.exe" - ForegroundColor Gray
62+ Write-Host " curl.exe -s -X POST http://localhost:8080/api/v1/chat/text -H 'Content-Type: application/json' -d '{\" message\" :\" 你好\" }'" - ForegroundColor White
0 commit comments