feat: 增强会话历史风险与绑定状态展示

This commit is contained in:
2026-06-04 03:38:51 +08:00
parent 9bca08001f
commit 742d5e9a42
3 changed files with 56 additions and 1 deletions

View File

@@ -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: