126 lines
3.8 KiB
Python
126 lines
3.8 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""
|
||
|
|
测试提示词生成功能的脚本
|
||
|
|
"""
|
||
|
|
import requests
|
||
|
|
import json
|
||
|
|
import time
|
||
|
|
|
||
|
|
def test_prompt_generation():
|
||
|
|
"""测试提示词生成功能"""
|
||
|
|
base_url = "http://localhost:5002"
|
||
|
|
|
||
|
|
# 测试数据
|
||
|
|
test_data = {
|
||
|
|
"input_text": "帮我写一个关于人工智能的演讲稿",
|
||
|
|
"template_id": "1"
|
||
|
|
}
|
||
|
|
|
||
|
|
print("🧪 开始测试提示词生成功能...")
|
||
|
|
print(f"测试URL: {base_url}")
|
||
|
|
print(f"测试数据: {test_data}")
|
||
|
|
print("-" * 50)
|
||
|
|
|
||
|
|
try:
|
||
|
|
# 发送POST请求
|
||
|
|
response = requests.post(
|
||
|
|
base_url,
|
||
|
|
data=test_data,
|
||
|
|
timeout=120, # 2分钟超时
|
||
|
|
headers={
|
||
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||
|
|
'User-Agent': 'TestScript/1.0'
|
||
|
|
}
|
||
|
|
)
|
||
|
|
|
||
|
|
print(f"📊 响应状态码: {response.status_code}")
|
||
|
|
print(f"📊 响应头: {dict(response.headers)}")
|
||
|
|
|
||
|
|
if response.status_code == 200:
|
||
|
|
print("✅ 请求成功!")
|
||
|
|
|
||
|
|
# 检查响应内容
|
||
|
|
if "生成的提示词" in response.text or "提示词生成成功" in response.text:
|
||
|
|
print("✅ 提示词生成功能正常!")
|
||
|
|
elif "提示词生成失败" in response.text:
|
||
|
|
print("❌ 提示词生成失败")
|
||
|
|
print(f"错误信息: {response.text[:500]}...")
|
||
|
|
else:
|
||
|
|
print("⚠️ 响应内容异常")
|
||
|
|
print(f"响应内容: {response.text[:500]}...")
|
||
|
|
|
||
|
|
elif response.status_code == 500:
|
||
|
|
print("❌ 服务器内部错误")
|
||
|
|
print(f"错误信息: {response.text[:500]}...")
|
||
|
|
else:
|
||
|
|
print(f"❌ 请求失败,状态码: {response.status_code}")
|
||
|
|
print(f"响应内容: {response.text[:500]}...")
|
||
|
|
|
||
|
|
except requests.exceptions.Timeout:
|
||
|
|
print("❌ 请求超时")
|
||
|
|
except requests.exceptions.ConnectionError:
|
||
|
|
print("❌ 连接失败,请检查服务器是否运行")
|
||
|
|
except Exception as e:
|
||
|
|
print(f"❌ 测试过程中发生错误: {str(e)}")
|
||
|
|
|
||
|
|
print("-" * 50)
|
||
|
|
print("🏁 测试完成")
|
||
|
|
|
||
|
|
def test_api_endpoint():
|
||
|
|
"""测试API端点"""
|
||
|
|
base_url = "http://localhost:5002"
|
||
|
|
|
||
|
|
print("🧪 测试API端点...")
|
||
|
|
|
||
|
|
# 测试GET请求
|
||
|
|
try:
|
||
|
|
response = requests.get(base_url, timeout=30)
|
||
|
|
if response.status_code == 200:
|
||
|
|
print("✅ GET请求正常")
|
||
|
|
else:
|
||
|
|
print(f"❌ GET请求失败: {response.status_code}")
|
||
|
|
except Exception as e:
|
||
|
|
print(f"❌ GET请求错误: {str(e)}")
|
||
|
|
|
||
|
|
# 测试微信API端点
|
||
|
|
wx_url = f"{base_url}/api/wx/generate"
|
||
|
|
wx_data = {
|
||
|
|
"input_text": "测试微信API",
|
||
|
|
"uid": 1
|
||
|
|
}
|
||
|
|
|
||
|
|
try:
|
||
|
|
response = requests.post(
|
||
|
|
wx_url,
|
||
|
|
json=wx_data,
|
||
|
|
timeout=60,
|
||
|
|
headers={'Content-Type': 'application/json'}
|
||
|
|
)
|
||
|
|
print(f"📊 微信API响应: {response.status_code}")
|
||
|
|
if response.status_code == 200:
|
||
|
|
print("✅ 微信API正常")
|
||
|
|
else:
|
||
|
|
print(f"❌ 微信API失败: {response.text[:200]}...")
|
||
|
|
except Exception as e:
|
||
|
|
print(f"❌ 微信API错误: {str(e)}")
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
print("🚀 启动提示词生成系统测试")
|
||
|
|
print("=" * 60)
|
||
|
|
|
||
|
|
# 测试API端点
|
||
|
|
test_api_endpoint()
|
||
|
|
print()
|
||
|
|
|
||
|
|
# 测试提示词生成
|
||
|
|
test_prompt_generation()
|
||
|
|
|
||
|
|
print("=" * 60)
|
||
|
|
print("📋 测试总结:")
|
||
|
|
print("1. 检查服务器是否运行在 localhost:5002")
|
||
|
|
print("2. 检查数据库连接是否正常")
|
||
|
|
print("3. 检查LLM API配置是否正确")
|
||
|
|
print("4. 查看日志文件获取详细错误信息")
|
||
|
|
|
||
|
|
|