From 0cb6f341354093925da28fbde3f9d0f5348b5e8e Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 31 Jul 2026 14:59:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20search=5Fresult.dspy=20=E7=94=A8=20Strea?= =?UTF-8?q?mHttpClient=20+=20try/except=20=E6=9B=BF=E4=BB=A3=E8=A3=B8=20ai?= =?UTF-8?q?ohttp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../knowledge_bases_list/search_result.dspy | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/wwwroot/knowledge_bases_list/search_result.dspy b/wwwroot/knowledge_bases_list/search_result.dspy index b0b7bf7..6c30748 100644 --- a/wwwroot/knowledge_bases_list/search_result.dspy +++ b/wwwroot/knowledge_bases_list/search_result.dspy @@ -29,25 +29,32 @@ if not query: ] }, ensure_ascii=False) -import aiohttp - -async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=20)) as s: - # 1. Embed - r = await s.post('https://embedding.opencomputing.net:10443/api/embed', +# 1. Embed +vec = [] +try: + client = StreamHttpClient() + resp = await client.request('POST', 'https://embedding.opencomputing.net:10443/api/embed', json={"texts": [query], "model": "CLIP-ViT-H-14"}) - emb = await r.json() if r.status == 200 else {} + emb = json.loads(resp) vec = emb.get("text_embeddings", emb.get("embeddings", [[]]))[0] - if not vec: - return json.dumps({"widgettype": "Text", "options": {"text": "向量化失败", "cfontsize": 14, "color": "#e74c3c"}}, ensure_ascii=False) +except: + pass +if not vec: + return json.dumps({"widgettype": "Text", "options": {"text": "向量化失败", "cfontsize": 14, "color": "#e74c3c"}}, ensure_ascii=False) - # 2. VDB search +# 2. VDB search +raw_rows = [] +try: recall_n = top_k * 3 - r2 = await s.post('https://vectordb.opencomputing.net:10443/v1/query', + client2 = StreamHttpClient() + resp2 = await client2.request('POST', 'https://vectordb.opencomputing.net:10443/v1/query', json={"colname": kb_id, "vector": vec, "pagerows": recall_n, "output_fields": ["*"]}) - vdb = await r2.json() if r2.status == 200 else {} + vdb = json.loads(resp2) raw_rows = vdb.get("data", {}).get("rows", []) if not isinstance(raw_rows, list): raw_rows = [] +except: + pass hits = [] for row in raw_rows: