forked from zhanggangyong/agent_management
91 lines
2.4 KiB
Python
91 lines
2.4 KiB
Python
"""
|
|
测试脚本 - 创建AI Agent
|
|
"""
|
|
import requests
|
|
import json
|
|
import sys
|
|
|
|
# 配置
|
|
BASE_URL = "http://localhost:8000"
|
|
|
|
|
|
def test_create_agent():
|
|
"""测试创建Agent"""
|
|
print("=" * 50)
|
|
print("测试: 创建AI Agent")
|
|
print("=" * 50)
|
|
|
|
# 测试数据
|
|
test_cases = [
|
|
{
|
|
"name": "test-echo-1",
|
|
"template": "echo_agent",
|
|
"config": {
|
|
"replicas": 1,
|
|
"cpu_request": "100m",
|
|
"cpu_limit": "500m",
|
|
"memory_request": "128Mi",
|
|
"memory_limit": "512Mi"
|
|
}
|
|
},
|
|
{
|
|
"name": "test-chat-1",
|
|
"template": "chat_agent",
|
|
"config": {
|
|
"replicas": 1,
|
|
"cpu_request": "200m",
|
|
"cpu_limit": "1000m",
|
|
"memory_request": "256Mi",
|
|
"memory_limit": "1Gi"
|
|
}
|
|
},
|
|
{
|
|
"name": "test-code-1",
|
|
"template": "code_agent",
|
|
"config": {
|
|
"replicas": 1
|
|
}
|
|
}
|
|
]
|
|
|
|
for i, test_data in enumerate(test_cases, 1):
|
|
print(f"\n测试用例 {i}: 创建 {test_data['name']}")
|
|
print(f"模板: {test_data['template']}")
|
|
print(f"配置: {json.dumps(test_data['config'], indent=2)}")
|
|
|
|
try:
|
|
response = requests.post(
|
|
f"{BASE_URL}/agents",
|
|
json=test_data,
|
|
headers={"Content-Type": "application/json"}
|
|
)
|
|
|
|
print(f"\n状态码: {response.status_code}")
|
|
|
|
if response.status_code == 200:
|
|
result = response.json()
|
|
print("✅ 创建成功!")
|
|
print(f"响应: {json.dumps(result, indent=2, ensure_ascii=False)}")
|
|
else:
|
|
print(f"❌ 创建失败!")
|
|
print(f"错误: {response.text}")
|
|
|
|
except Exception as e:
|
|
print(f"❌ 请求失败: {str(e)}")
|
|
|
|
print("-" * 50)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
# 先检查服务是否可用
|
|
print("检查服务状态...")
|
|
response = requests.get(f"{BASE_URL}")
|
|
print(f"服务状态: {response.json()}\n")
|
|
|
|
test_create_agent()
|
|
|
|
except requests.exceptions.ConnectionError:
|
|
print("❌ 无法连接到服务。请确保服务正在运行: python app.py")
|
|
sys.exit(1)
|