| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- 混合检索HTTP服务请求示例
- 使用Python requests库调用混合检索接口
- """
- import requests
- import json
- def hybrid_search_example():
- """
- 混合检索接口调用示例
- """
- # 服务地址
- base_url = "http://localhost:18001"
- endpoint = "/hybrid_search"
- url = f"{base_url}{endpoint}"
-
- # 示例1:基本请求(仅文本查询)
- print("示例1:基本请求(仅文本查询)")
- payload1 = {
- "text_query": "这是一个测试文本查询",
- "topn": 2
- }
-
- response1 = requests.post(url, json=payload1)
- print(f"状态码: {response1.status_code}")
- print(f"响应内容: {json.dumps(response1.json(), indent=2, ensure_ascii=False)}")
-
- # 示例2:完整请求(文本+图片)
- print("\n示例2:完整请求(文本+图片)")
- payload2 = {
- "text_query": "这是一个带图片的测试查询",
- "image": "https://example.com/test.jpg",
- "topn": 5
- }
-
- response2 = requests.post(url, json=payload2)
- print(f"状态码: {response2.status_code}")
- print(f"响应内容: {json.dumps(response2.json(), indent=2, ensure_ascii=False)}")
-
- # 示例3:使用默认topn值
- print("\n示例3:使用默认topn值")
- payload3 = {
- "text_query": "这是一个使用默认值的测试",
- "image": "https://example.com/another.jpg"
- }
-
- response3 = requests.post(url, json=payload3)
- print(f"状态码: {response3.status_code}")
- print(f"响应内容: {json.dumps(response3.json(), indent=2, ensure_ascii=False)}")
- if __name__ == "__main__":
- hybrid_search_example()
|