Files
assistant/tests/test_all_faq.sh

75 lines
2.2 KiB
Bash
Raw Normal View History

#!/bin/bash
# 测试所有 FAQ 分类
echo "=========================================="
echo "🧪 测试所有 FAQ 分类"
echo "=========================================="
echo ""
# 定义测试用例
declare -A TEST_CASES=(
["订单相关"]="How do I place an order?"
["支付相关"]="What payment methods do you accept?"
["运输相关"]="What are the shipping options?"
["退货相关"]="I received a defective item, what should I do?"
["账号相关"]="I forgot my password, now what?"
["营业时间"]="What are your opening hours?"
)
# 测试每个分类
for category in "${!TEST_CASES[@]}"; do
question="${TEST_CASES[$category]}"
conv_id="test_${category}___$(date +%s)"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📋 分类: $category"
echo "📝 问题: $question"
echo "⏳ 处理中..."
echo ""
# 调用 API
RESPONSE=$(docker exec ai_agent curl -s -X POST 'http://localhost:8000/api/agent/query' \
-H 'Content-Type: application/json' \
-d "{\"conversation_id\":\"$conv_id\",\"user_id\":\"test_user\",\"account_id\":\"2\",\"message\":\"$question\"}")
# 解析并显示结果
echo "$RESPONSE" | python3 << PYTHON
import json
import sys
try:
data = json.load(sys.stdin)
# 提取响应
response = data.get("response", "")
intent = data.get("intent", "")
if response:
# 清理 HTML 标签(如果有)
import re
clean_response = re.sub(r'<[^<]+?>', '', response)
clean_response = clean_response.strip()
# 截断过长响应
if len(clean_response) > 300:
clean_response = clean_response[:300] + "..."
print(f"🎯 意图: {intent}")
print(f"🤖 回答: {clean_response}")
else:
print("❌ 未获得回答")
print(f"调试信息: {json.dumps(data, indent=2, ensure_ascii=False)}")
except Exception as e:
print(f"❌ 解析错误: {e}")
print(f"原始响应: {sys.stdin.read()}")
PYTHON
echo ""
sleep 2 # 间隔 2 秒
done
echo "=========================================="
echo "✅ 所有测试完成"
echo "=========================================="