fix:客服agent的bug修复
This commit is contained in:
+12
-2
@@ -26,7 +26,17 @@ async def intent_recognize(query: str, *, llm_client) -> Intent:
|
||||
messages = [
|
||||
{
|
||||
"role": "system",
|
||||
"content": "仅返回一个意图枚举值,不要输出解释。",
|
||||
"content": (
|
||||
"你是一个意图分类器。请根据用户输入,从以下选项中选择最匹配的意图,"
|
||||
"并仅输出对应的英文标签(不输出任何其他内容):\n"
|
||||
"- guide_purchase: 用户询问如何购买基金、开户、注册等引导类问题\n"
|
||||
"- want_advisor: 用户希望获得个性化基金推荐或投资顾问服务\n"
|
||||
"- knowledge_qa: 用户询问基金相关的知识性问题,如净值、费率、风险等\n"
|
||||
"- nl2sql_request: 用户要求查询具体数据或账户信息\n"
|
||||
"- complain: 用户表达不满或投诉\n"
|
||||
"- no_match: 以上都不匹配\n"
|
||||
"仅输出一个小写英文标签,不要输出解释、标点或换行。"
|
||||
),
|
||||
},
|
||||
{"role": "user", "content": query},
|
||||
]
|
||||
@@ -36,4 +46,4 @@ async def intent_recognize(query: str, *, llm_client) -> Intent:
|
||||
logger.exception("intent recognition failed")
|
||||
return Intent.NO_MATCH
|
||||
value = raw.strip().strip('`').lower()
|
||||
return Intent(value) if value in INTENT_VALUES else Intent.NO_MATCH
|
||||
return Intent(value) if value in INTENT_VALUES else Intent.NO_MATCH
|
||||
+10
-5
@@ -11,9 +11,9 @@ logger = logging.getLogger("rag.retrieve")
|
||||
|
||||
|
||||
BUSINESS_RETRIEVAL = (
|
||||
("fin_faq", "faq", 3, 0.75),
|
||||
("fin_fund_doc", "funddoc", 5, 0.70),
|
||||
("fin_policy", "policy", 5, 0.70),
|
||||
("fin_faq", "faq", 3, 0.40),
|
||||
("fin_fund_doc", "funddoc", 5, 0.35),
|
||||
("fin_policy", "policy", 5, 0.35),
|
||||
)
|
||||
|
||||
|
||||
@@ -87,7 +87,12 @@ def _format_candidates(candidates) -> list[dict]:
|
||||
threshold = candidate["threshold"]
|
||||
for hit in _flatten_hits(candidate["results"]):
|
||||
entity = hit.get("entity") or hit
|
||||
score = hit.get("distance", hit.get("score"))
|
||||
distance = hit.get("distance")
|
||||
raw_score = hit.get("score")
|
||||
if distance is not None:
|
||||
score = 1.0 - distance
|
||||
else:
|
||||
score = raw_score
|
||||
if score is None or score < threshold:
|
||||
continue
|
||||
sources.append(
|
||||
@@ -155,4 +160,4 @@ async def retrieve_with_status(
|
||||
except Exception:
|
||||
logger.exception("Milvus retrieval failed")
|
||||
return {"status": "milvus_unavailable", "sources": []}
|
||||
return {"status": "ok", "sources": _format_candidates(candidates)}
|
||||
return {"status": "ok", "sources": _format_candidates(candidates)}
|
||||
Reference in New Issue
Block a user