rag
This commit is contained in:
parent
d629f483dc
commit
353a99802c
@ -14,11 +14,25 @@ class APIService:
|
|||||||
"""调用嵌入服务获取文本向量"""
|
"""调用嵌入服务获取文本向量"""
|
||||||
try:
|
try:
|
||||||
uapi = UAPI(request, DictObject(**globals()))
|
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}
|
params_kw = {"input": texts}
|
||||||
b = await uapi.call(upappid, apiname, user, params_kw)
|
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"):
|
if d.get("object") != "list" or not d.get("data"):
|
||||||
error(f"嵌入服务响应格式错误: {d}")
|
error(f"嵌入服务响应格式错误: {d}")
|
||||||
raise RuntimeError("嵌入服务响应格式错误")
|
raise RuntimeError("嵌入服务响应格式错误")
|
||||||
@ -26,7 +40,7 @@ class APIService:
|
|||||||
debug(f"成功获取 {len(embeddings)} 个嵌入向量")
|
debug(f"成功获取 {len(embeddings)} 个嵌入向量")
|
||||||
return embeddings
|
return embeddings
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error(f"嵌入服务调用失败: {str(e)}")
|
error(f"嵌入服务调用失败: {str(e)}, upappid={upappid}, apiname={apiname}")
|
||||||
raise RuntimeError(f"嵌入服务调用失败: {str(e)}")
|
raise RuntimeError(f"嵌入服务调用失败: {str(e)}")
|
||||||
|
|
||||||
# 实体提取服务 (LTP/small)
|
# 实体提取服务 (LTP/small)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user