feat:修复投顾agent功能

This commit is contained in:
2026-09-15 09:24:30 +08:00
parent b75ab5ecdc
commit 9660323ff2
7 changed files with 150 additions and 30 deletions
+19 -1
View File
@@ -21,6 +21,24 @@ _REFERENCE_TERMS = (
"这个基金", "该基金", "那只基金", "这只基金", "这个结果", "上一轮", "刚才", "前面",
)
_CUSTOMER_RISK_LABELS = {
"保守型": "C1",
"稳健型": "C2",
"平衡型": "C3",
"进取型": "C4",
"激进型": "C5",
}
def _normalize_customer_risk_label(question: str) -> str:
"""将展示层客户风险标签规范化为数据库 C1-C5 编码。"""
normalized = re.sub(r"\s+", "", question)
if "客户" not in normalized and "风险" not in normalized:
return normalized
for label, code in _CUSTOMER_RISK_LABELS.items():
normalized = normalized.replace(label, code)
return normalized
def _rewrite_explicit_customer_identity(question: str) -> str | None:
normalized = re.sub(r"\s+", "", question)
@@ -63,7 +81,7 @@ async def rewrite_query(
llm_client=llm,
) -> str:
"""使用有限会话上下文补全问题;改写失败时安全返回原问题。"""
original = (question or "").strip()
original = _normalize_customer_risk_label((question or "").strip())
context = (conversation_context or "").strip()
if not original:
return original
+3 -3
View File
@@ -18,12 +18,12 @@
"value_hint": "fin_product.product_type 实际枚举值为:货币型/债券型/混合型/股票型/指数型/QDII;股票型基金必须用 product_type = '股票型',不要使用 Schema 注释里的'股票基金'"
},
{
"term": "客户",
"term": "客户风险等级",
"enabled": true,
"aliases": ["客户", "投资人", "持有人"],
"aliases": ["客户", "投资人", "持有人", "风险评级", "风险等级", "风险类型", "激进型", "进取型", "平衡型", "稳健型", "保守型", "C1", "C2", "C3", "C4", "C5"],
"tables": ["fin_customer_profile", "fin_holdings", "fin_risk_assessment"],
"fields": ["customer_id", "risk_level", "customer_level"],
"value_hint": "fin_customer_profile.risk_level / fin_risk_assessment.risk_level 实际枚举值为 R1-R5(R1 最保守,R5 最激进,与产品风险等级同一口径);查'保守型/稳健型客户'对应 R1/R2,'激进型客户'对应 R5"
"value_hint": "客户风险字段实际枚举值为 C1-C5(C1 最保守,C5 最激进);展示层映射为保守型=C1、稳健型=C2、平衡型=C3、进取型=C4、激进型=C5。产品风险等级才使用 R1-R5"
},
{
"term": "持仓",