File size: 1,239 Bytes
59bd45e | 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 | """测试 Chat API"""
import requests
def test_chat_api():
"""测试聊天 API"""
url = "http://172.18.16.245:8000/api/chat"
print("=" * 50)
print("测试 Chat API")
print("=" * 50)
print(f"URL: {url}")
# 测试数据
data = {
'text': '你好,今天天气怎么样?'
}
print(f"\n发送消息: {data['text']}")
print("等待响应...")
try:
response = requests.post(url, data=data, timeout=60)
print(f"\n状态码: {response.status_code}")
print(f"响应头: {dict(response.headers)}")
if response.status_code == 200:
result = response.json()
print(f"\n✅ 成功!")
print(f"AI 回复: {result.get('response', 'No response')}")
else:
print(f"\n❌ 失败!")
print(f"错误: {response.text}")
except requests.exceptions.Timeout:
print("\n❌ 请求超时!")
except requests.exceptions.ConnectionError:
print("\n❌ 连接失败! 请确保服务器正在运行")
except Exception as e:
print(f"\n❌ 错误: {e}")
print("\n" + "=" * 50)
if __name__ == "__main__":
test_chat_api()
|