-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api.py
More file actions
85 lines (67 loc) · 2.92 KB
/
test_api.py
File metadata and controls
85 lines (67 loc) · 2.92 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python3
"""
Script để test các agent APIs với schema đơn giản
"""
import asyncio
import json
import aiohttp
API_BASE = "http://localhost:8000/api/v1"
async def test_agents():
"""Test tất cả các agents"""
async with aiohttp.ClientSession() as session:
# 1. Liệt kê tất cả agents
print("=== DANH SÁCH AGENTS ===")
async with session.get(f"{API_BASE}/agents/") as resp:
agents = await resp.json()
print(json.dumps(agents, indent=2, ensure_ascii=False))
print("\n" + "="*50 + "\n")
# 2. Test LLM Agent
print("=== TEST LLM AGENT ===")
llm_request = {
"text": "Hãy viết một câu chuyện ngắn về trí tuệ nhân tạo"
}
async with session.post(f"{API_BASE}/agents/llm_agent/process",
json=llm_request) as resp:
result = await resp.json()
print(json.dumps(result, indent=2, ensure_ascii=False))
print("\n" + "="*50 + "\n")
# 3. Test Vision Agent
print("=== TEST VISION AGENT ===")
vision_request = {
"image": "https://example.com/sample-image.jpg"
}
async with session.post(f"{API_BASE}/agents/vision_agent/process",
json=vision_request) as resp:
result = await resp.json()
print(json.dumps(result, indent=2, ensure_ascii=False))
print("\n" + "="*50 + "\n")
# 4. Test File Processing Agent
print("=== TEST FILE PROCESSING AGENT ===")
file_request = {
"file": "https://example.com/sample-document.pdf"
}
async with session.post(f"{API_BASE}/agents/file_processing_agent/process",
json=file_request) as resp:
result = await resp.json()
print(json.dumps(result, indent=2, ensure_ascii=False))
print("\n" + "="*50 + "\n")
# 5. Test với nhiều input types (chỉ text sẽ được xử lý)
print("=== TEST MIXED INPUT ===")
mixed_request = {
"text": "Phân tích hình ảnh này",
"image": "https://example.com/image.jpg"
}
async with session.post(f"{API_BASE}/agents/llm_agent/process",
json=mixed_request) as resp:
result = await resp.json()
print("LLM Agent chỉ xử lý text:")
print(json.dumps(result, indent=2, ensure_ascii=False))
if __name__ == "__main__":
print("Bắt đầu test API...")
print("Đảm bảo server đang chạy: uvicorn app.main:app --reload")
print("="*60)
try:
asyncio.run(test_agents())
except Exception as e:
print(f"Lỗi khi test: {e}")
print("Hãy kiểm tra server có đang chạy không?")