test_http_hybrid_search.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env python3
  2. """
  3. 测试混合检索HTTP服务
  4. """
  5. import requests
  6. import json
  7. # 测试数据 - JSON-RPC 2.0格式
  8. test_data = {
  9. "jsonrpc": "2.0",
  10. "method": "hybrid_search",
  11. "params": {
  12. "text_query": "测试",
  13. "image": "https://example.com/image.jpg",
  14. "topn": 2
  15. },
  16. "id": "test-123"
  17. }
  18. # 发送POST请求
  19. def test_hybrid_search():
  20. headers = {
  21. "Content-Type": "application/json",
  22. "Accept": "application/json, text/event-stream"
  23. }
  24. # 尝试不同的URL路径
  25. test_urls = [
  26. "http://localhost:18000",
  27. "http://localhost:18000/mcp",
  28. "http://localhost:18000/tools/hybrid_search",
  29. "http://localhost:18000/api/hybrid_search"
  30. ]
  31. print("开始测试混合检索HTTP服务...")
  32. print(f"请求数据: {json.dumps(test_data, indent=2, ensure_ascii=False)}")
  33. for url in test_urls:
  34. print(f"\n尝试URL: {url}")
  35. try:
  36. # 发送POST请求
  37. response = requests.post(url, headers=headers, json=test_data, timeout=10)
  38. # 打印响应结果
  39. print(f"响应状态码: {response.status_code}")
  40. print(f"响应内容: {response.text[:200]}...")
  41. if response.status_code == 200:
  42. # 解析JSON响应
  43. response_data = response.json()
  44. print(f"解析后的响应数据: {json.dumps(response_data, indent=2, ensure_ascii=False)}")
  45. print("测试成功!")
  46. return
  47. except Exception as e:
  48. print(f"请求失败: {str(e)}")
  49. print("所有URL路径都测试失败")
  50. if __name__ == "__main__":
  51. test_hybrid_search()