| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- #!/usr/bin/env python3
- """
- 测试混合检索HTTP服务
- """
- import requests
- import json
- # 测试数据 - JSON-RPC 2.0格式
- test_data = {
- "jsonrpc": "2.0",
- "method": "hybrid_search",
- "params": {
- "text_query": "测试",
- "image": "https://example.com/image.jpg",
- "topn": 2
- },
- "id": "test-123"
- }
- # 发送POST请求
- def test_hybrid_search():
- headers = {
- "Content-Type": "application/json",
- "Accept": "application/json, text/event-stream"
- }
-
- # 尝试不同的URL路径
- test_urls = [
- "http://localhost:18000",
- "http://localhost:18000/mcp",
- "http://localhost:18000/tools/hybrid_search",
- "http://localhost:18000/api/hybrid_search"
- ]
-
- print("开始测试混合检索HTTP服务...")
- print(f"请求数据: {json.dumps(test_data, indent=2, ensure_ascii=False)}")
-
- for url in test_urls:
- print(f"\n尝试URL: {url}")
- try:
- # 发送POST请求
- response = requests.post(url, headers=headers, json=test_data, timeout=10)
-
- # 打印响应结果
- print(f"响应状态码: {response.status_code}")
- print(f"响应内容: {response.text[:200]}...")
-
- if response.status_code == 200:
- # 解析JSON响应
- response_data = response.json()
- print(f"解析后的响应数据: {json.dumps(response_data, indent=2, ensure_ascii=False)}")
- print("测试成功!")
- return
- except Exception as e:
- print(f"请求失败: {str(e)}")
-
- print("所有URL路径都测试失败")
- if __name__ == "__main__":
- test_hybrid_search()
|