You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
2.8 KiB
108 lines
2.8 KiB
"""
|
|
API接口测试脚本
|
|
"""
|
|
|
|
import requests
|
|
import json
|
|
|
|
|
|
def test_agent_api():
|
|
"""测试Agent API"""
|
|
|
|
print("=" * 80)
|
|
print("API接口测试")
|
|
print("=" * 80)
|
|
print()
|
|
|
|
# API地址
|
|
url = "http://localhost:8001/api/agent"
|
|
|
|
# 测试用例
|
|
test_cases = [
|
|
{
|
|
"name": "美食类内容",
|
|
"query": "我想做一些美食相关的短视频,主要是家常菜的制作教程"
|
|
},
|
|
{
|
|
"name": "校园类内容",
|
|
"query": "我想拍一些关于大学生活的有趣视频,记录校园日常"
|
|
},
|
|
{
|
|
"name": "健身类内容",
|
|
"query": "我想做一些关于健身的短视频,分享简单的居家锻炼方法"
|
|
}
|
|
]
|
|
|
|
# 选择测试用例
|
|
print("可用的测试用例:")
|
|
for i, case in enumerate(test_cases, 1):
|
|
print(f"{i}. {case['name']}: {case['query']}")
|
|
print()
|
|
|
|
choice = input("选择测试用例(1-3,直接回车选择1): ").strip()
|
|
|
|
if not choice:
|
|
choice = "1"
|
|
|
|
try:
|
|
test_index = int(choice) - 1
|
|
if test_index < 0 or test_index >= len(test_cases):
|
|
test_index = 0
|
|
except ValueError:
|
|
test_index = 0
|
|
|
|
selected_test = test_cases[test_index]
|
|
|
|
print(f"\n测试: {selected_test['name']}")
|
|
print(f"查询: {selected_test['query']}")
|
|
print()
|
|
|
|
# 构建请求
|
|
payload = {
|
|
"query": selected_test['query'],
|
|
"max_iterations": 15
|
|
}
|
|
|
|
print("正在调用API...")
|
|
print(f"URL: {url}")
|
|
print(f"Payload: {json.dumps(payload, ensure_ascii=False, indent=2)}")
|
|
print()
|
|
|
|
try:
|
|
# 发送请求
|
|
response = requests.post(url, json=payload, timeout=300)
|
|
|
|
print("=" * 80)
|
|
print("响应")
|
|
print("=" * 80)
|
|
print()
|
|
|
|
if response.status_code == 200:
|
|
result = response.json()
|
|
|
|
if result.get("success"):
|
|
print("✓ 成功!")
|
|
print()
|
|
print(result.get("final_answer", ""))
|
|
print()
|
|
print(f"迭代次数: {result.get('iteration')}")
|
|
print(f"工具调用: {len(result.get('tool_calls', []))}")
|
|
else:
|
|
print("✗ 失败")
|
|
print(f"错误: {result.get('error')}")
|
|
else:
|
|
print(f"✗ HTTP错误: {response.status_code}")
|
|
print(response.text)
|
|
|
|
except requests.exceptions.ConnectionError:
|
|
print("✗ 连接失败")
|
|
print()
|
|
print("请确保API服务已启动:")
|
|
print(" python api.py")
|
|
print()
|
|
except Exception as e:
|
|
print(f"✗ 出错: {e}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_agent_api()
|
|
|