From 742d5e9a423a5e7d5e9d66142fb0616998518ec1 Mon Sep 17 00:00:00 2001 From: bruce Date: Thu, 4 Jun 2026 03:38:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=BC=BA=E4=BC=9A=E8=AF=9D?= =?UTF-8?q?=E5=8E=86=E5=8F=B2=E9=A3=8E=E9=99=A9=E4=B8=8E=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/chat/views.py | 27 +++++++++++++++++++++++++++ templates/chat/index.html | 7 ++++++- tests/test_chat.py | 23 +++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/apps/chat/views.py b/apps/chat/views.py index 4290a03..3e19333 100644 --- a/apps/chat/views.py +++ b/apps/chat/views.py @@ -26,6 +26,7 @@ def index(request): { "conversation": None, "conversations": [], + "conversation_history": [], "form": ChatForm(), "documents": [], "result": None, @@ -91,6 +92,7 @@ def detail(request, conversation_id: str): export_card = _build_export_card(result, conversation) risk_card = _build_risk_card(result, conversation) notify_card = _build_notify_card(result, conversation) + conversation_history = _build_conversation_history(Conversation.objects.all()) return render( request, @@ -98,6 +100,7 @@ def detail(request, conversation_id: str): { "conversation": conversation, "conversations": Conversation.objects.all(), + "conversation_history": conversation_history, "batch": batch, "form": form, "documents": documents, @@ -276,6 +279,30 @@ def _build_prompt_templates() -> list[str]: ] +def _build_conversation_history(conversations) -> list[dict]: + """ + 组装左栏会话历史摘要。 + + 左栏只展示稳定摘要字段,不在模板里拼风险判断逻辑。 + """ + history = [] + for item in conversations: + node_status_map = {node.get("label"): node.get("status", "") for node in item.node_results} + risk_status = node_status_map.get("风险预警", "待处理") + history.append( + { + "conversation_id": item.conversation_id, + "title": item.title, + "product_name": item.product_name, + "batch_id": item.batch_id, + "risk_level": "高" if risk_status in {"已阻断", "待复核"} else "中", + "updated_at": item.updated_at, + "batch_binding_label": "已绑定资料包" if item.batch_id else "未绑定资料包", + } + ) + return history + + def _build_analysis_card(result: AgentResult | None, conversation: Conversation) -> dict: structured_output = {} if result and result.structured_output: diff --git a/templates/chat/index.html b/templates/chat/index.html index a460280..ea0279a 100644 --- a/templates/chat/index.html +++ b/templates/chat/index.html @@ -49,11 +49,16 @@

会话历史

左侧保留历史会话,标题默认使用解析后的产品名称。