feat:修改投顾agent和nl2sql的功能

This commit is contained in:
2026-09-13 23:46:15 +08:00
parent 4dcfcbeb3a
commit 958b785b04
11 changed files with 436 additions and 61 deletions
+24 -3
View File
@@ -31,10 +31,31 @@ async def summarize_result(
llm_client,
max_prompt_rows: int = 20,
) -> str:
"""使用脱敏后的受控结果生成摘要,模型失败时返回固定话术。"""
"""兼容旧调用方:返回面向用户的自然语言答案。"""
return await render_answer(
question,
columns,
rows,
llm_client=llm_client,
max_prompt_rows=max_prompt_rows,
)
async def render_answer(
question: str,
columns: list[str],
rows: list[dict[str, Any]],
*,
llm_client,
max_prompt_rows: int = 20,
) -> str:
"""将受控查询结果渲染为用户回答,不输出原始 JSON 或无关字段。"""
fallback = f"查询完成,共返回 {len(rows)} 条记录。"
prompt = (
"请用简洁中文总结查询结果,只基于提供的数据,不要猜测。\n"
"请根据用户问题生成简洁、准确的中文业务回答。\n"
"只使用查询结果中的必要字段回答问题,不要输出 JSON、SQL、Markdown 表格或内部字段名。\n"
"如果有多条记录,优先做合计、数量或关键项概括;只有用户明确需要明细时才列出明细。\n"
"不得补充查询结果中没有的数据,不要解释你的处理过程。\n"
f"问题:{question}\n"
f"列名:{json.dumps(columns, ensure_ascii=False)}\n"
f"结果:{json.dumps(rows[:max_prompt_rows], ensure_ascii=False, default=str)}"
@@ -42,7 +63,7 @@ async def summarize_result(
try:
answer = await llm_client.chat(
[
{"role": "system", "content": "你是数据查询结果摘要助手。"},
{"role": "system", "content": "你是基金平台的数据回答助手。不要输出 JSON。"},
{"role": "user", "content": prompt},
],
temperature=0,