Clarify chat retrieval failures
This commit is contained in:
@@ -107,7 +107,7 @@ class ChatService:
|
||||
db.commit()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_502_BAD_GATEWAY,
|
||||
detail="外部服务暂时不可用,请稍后再试",
|
||||
detail=str(exc),
|
||||
) from exc
|
||||
cost_ms = int((perf_counter() - started_at) * 1000)
|
||||
|
||||
|
||||
@@ -267,8 +267,14 @@ class FeishuKnowledgeService:
|
||||
if config.search_url:
|
||||
try:
|
||||
return cls._retrieve_from_search(question, scopes, config)
|
||||
except ExternalServiceError:
|
||||
pass
|
||||
except ExternalServiceError as exc:
|
||||
try:
|
||||
return cls._retrieve_from_feishu(question, scopes)
|
||||
except ExternalServiceError as fallback_exc:
|
||||
raise ExternalServiceError(
|
||||
f"{exc};飞书直读也失败:{fallback_exc}",
|
||||
provider="feishu",
|
||||
) from fallback_exc
|
||||
return cls._retrieve_from_feishu(question, scopes)
|
||||
|
||||
@classmethod
|
||||
@@ -298,19 +304,34 @@ class FeishuKnowledgeService:
|
||||
"""从飞书知识库检索文档内容"""
|
||||
from app.services.rag_service import RetrievedChunk
|
||||
|
||||
settings = get_settings()
|
||||
if not settings.feishu_app_id or not settings.feishu_app_secret:
|
||||
raise ExternalServiceError(
|
||||
"未配置飞书应用凭证,无法读取飞书知识库。请配置 FEISHU_APP_ID/FEISHU_APP_SECRET,"
|
||||
"或在系统配置中填写可用的飞书搜索接口地址。",
|
||||
provider="feishu",
|
||||
)
|
||||
|
||||
# 收集所有文档片段
|
||||
all_chunks: list[tuple[KnowledgeScope, str, str, str | None]] = []
|
||||
load_errors: list[str] = []
|
||||
|
||||
for scope in scopes:
|
||||
try:
|
||||
documents = cls._load_documents(scope)
|
||||
except ExternalServiceError:
|
||||
except ExternalServiceError as exc:
|
||||
load_errors.append(f"{scope.name}:{exc}")
|
||||
continue
|
||||
|
||||
for title, content, source_url in documents:
|
||||
all_chunks.append((scope, title, content, source_url))
|
||||
|
||||
if not all_chunks:
|
||||
if load_errors:
|
||||
raise ExternalServiceError(
|
||||
"飞书知识库读取失败:" + ";".join(load_errors[:3]),
|
||||
provider="feishu",
|
||||
)
|
||||
return []
|
||||
|
||||
# 关键词匹配评分(简单但够用的检索方式)
|
||||
|
||||
Reference in New Issue
Block a user