Files
tsp-assistant/quick_verify.py
2025-09-06 21:06:18 +08:00

106 lines
3.6 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
快速验证修复结果
"""
import requests
import json
import time
def test_fixes():
"""测试修复的功能"""
base_url = "http://localhost:5000"
print("🔧 快速验证修复结果")
print("="*50)
# 1. 测试Agent模式切换
print("1. 测试Agent模式切换...")
try:
response = requests.post(f"{base_url}/api/agent/toggle",
json={"enabled": True})
if response.status_code == 200:
data = response.json()
if data.get("success"):
print(" ✅ Agent模式切换成功")
else:
print(" ❌ Agent模式切换失败")
else:
print(f" ❌ HTTP错误: {response.status_code}")
except Exception as e:
print(f" ❌ 请求错误: {e}")
# 2. 测试知识库添加
print("\n2. 测试知识库添加...")
try:
test_knowledge = {
"question": "测试问题 - 快速验证",
"answer": "这是一个测试答案,用于验证知识库添加功能。",
"category": "技术问题",
"confidence_score": 0.9
}
response = requests.post(f"{base_url}/api/knowledge",
json=test_knowledge)
if response.status_code == 200:
data = response.json()
if data.get("success"):
print(" ✅ 知识库添加成功")
else:
print(" ❌ 知识库添加失败")
else:
print(f" ❌ HTTP错误: {response.status_code}")
except Exception as e:
print(f" ❌ 请求错误: {e}")
# 3. 测试文件上传
print("\n3. 测试文件上传...")
try:
with open("test_sample.txt", "rb") as f:
files = {"file": ("test_sample.txt", f, "text/plain")}
data = {
"process_method": "auto",
"category": "技术问题",
"confidence_score": 0.8
}
response = requests.post(f"{base_url}/api/knowledge/upload",
files=files, data=data)
if response.status_code == 200:
result = response.json()
if result.get("success"):
print(f" ✅ 文件上传成功,生成 {result.get('knowledge_count', 0)} 条知识")
else:
print(f" ❌ 文件上传失败: {result.get('error', '未知错误')}")
else:
print(f" ❌ HTTP错误: {response.status_code}")
except Exception as e:
print(f" ❌ 请求错误: {e}")
# 4. 测试Agent状态获取
print("\n4. 测试Agent状态获取...")
try:
response = requests.get(f"{base_url}/api/agent/status")
if response.status_code == 200:
data = response.json()
if data.get("success"):
print(f" ✅ Agent状态: {data.get('status', 'unknown')}")
print(f" ✅ 可用工具: {data.get('available_tools', 0)}")
else:
print(" ❌ Agent状态获取失败")
else:
print(f" ❌ HTTP错误: {response.status_code}")
except Exception as e:
print(f" ❌ 请求错误: {e}")
print("\n" + "="*50)
print("🎉 快速验证完成!")
print("如果所有测试都通过,说明修复成功。")
print("如果还有问题,请运行完整测试脚本:")
print("python comprehensive_frontend_test.py")
if __name__ == "__main__":
test_fixes()