From 353a99802c94c42243860c27354c0614987170f6 Mon Sep 17 00:00:00 2001 From: wangmeihua <13383952685@163.com> Date: Wed, 13 Aug 2025 11:23:20 +0800 Subject: [PATCH] rag --- rag/uapi_service.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/rag/uapi_service.py b/rag/uapi_service.py index b4f1b95..df8f7d0 100644 --- a/rag/uapi_service.py +++ b/rag/uapi_service.py @@ -14,11 +14,25 @@ class APIService: """调用嵌入服务获取文本向量""" try: uapi = UAPI(request, DictObject(**globals())) - debug(f'{uapi=}, {type(uapi.call)}') + debug( + f'{uapi=}, {type(uapi.call)}, upappid={upappid}, apiname={apiname}, user={user}, texts={texts[:2]}') # 仅记录前两个文本以避免日志过长 params_kw = {"input": texts} b = await uapi.call(upappid, apiname, user, params_kw) - debug(f'{b=}, {type(b)}') - d = json.loads(b.decode('utf-8')) + # 检查响应内容 + if not b: + error(f"嵌入服务返回空响应: upappid={upappid}, apiname={apiname}") + raise RuntimeError("嵌入服务返回空响应") + try: + response_text = b.decode('utf-8') + except UnicodeDecodeError as decode_err: + error(f"响应解码失败: {str(decode_err)}, 原始响应: {b[:100]}") # 记录前100字节 + raise RuntimeError(f"响应解码失败: {str(decode_err)}") + debug(f"嵌入服务原始响应: {response_text[:500]}") # 记录前500字符以避免日志过长 + try: + d = json.loads(response_text) + except json.JSONDecodeError as json_err: + error(f"JSON 解析失败: {str(json_err)}, 响应内容: {response_text[:500]}") + raise RuntimeError(f"JSON 解析失败: {str(json_err)}") if d.get("object") != "list" or not d.get("data"): error(f"嵌入服务响应格式错误: {d}") raise RuntimeError("嵌入服务响应格式错误") @@ -26,7 +40,7 @@ class APIService: debug(f"成功获取 {len(embeddings)} 个嵌入向量") return embeddings except Exception as e: - error(f"嵌入服务调用失败: {str(e)}") + error(f"嵌入服务调用失败: {str(e)}, upappid={upappid}, apiname={apiname}") raise RuntimeError(f"嵌入服务调用失败: {str(e)}") # 实体提取服务 (LTP/small)