diff --git a/apps/chat/views.py b/apps/chat/views.py index c9b5c02..e230d74 100644 --- a/apps/chat/views.py +++ b/apps/chat/views.py @@ -85,6 +85,8 @@ def detail(request, conversation_id: str): active_node = "risk" conversation.refresh_from_db() workspace_summary = _build_workspace_summary(conversation, batch) + conversation_context = _build_conversation_context(conversation, batch, workspace_summary) + prompt_templates = _build_prompt_templates() export_card = _build_export_card(result, conversation) risk_card = _build_risk_card(result, conversation) notify_card = _build_notify_card(result, conversation) @@ -105,6 +107,8 @@ def detail(request, conversation_id: str): "node_results": conversation.node_results, "active_node": active_node, "workspace_summary": workspace_summary, + "conversation_context": conversation_context, + "prompt_templates": prompt_templates, "upload_form": upload_form, "export_card": export_card, "risk_card": risk_card, @@ -246,6 +250,30 @@ def _build_workspace_summary(conversation: Conversation, batch: SubmissionBatch } +def _build_conversation_context( + conversation: Conversation, + batch: SubmissionBatch | None, + workspace_summary: dict, +) -> dict: + return { + "batch_id": conversation.batch_id, + "product_name": conversation.product_name, + "workflow_type": batch.workflow_type if batch else "registration", + "task_status": conversation.task_status, + "highest_risk_level": workspace_summary.get("highest_risk_level", "-"), + "export_allowed": workspace_summary.get("export_allowed", "-"), + } + + +def _build_prompt_templates() -> list[str]: + return [ + "请汇总当前资料包的章节点、页数和目录覆盖情况", + "请检查当前资料包缺失了哪些必交项和错放项", + "请抽取当前资料包的核心字段并标记低置信度项", + "请给出当前资料包的高风险项、责任人和整改建议", + ] + + def _build_export_card(result: AgentResult | None, conversation: Conversation) -> dict: """ 统一组装 Word 导出能力卡上下文。 diff --git a/templates/chat/index.html b/templates/chat/index.html index 6dbe968..23c8db5 100644 --- a/templates/chat/index.html +++ b/templates/chat/index.html @@ -16,6 +16,33 @@ {% endif %} + {% if conversation %} +
+
+

顶部对话上下文

+

进入会话后,先用当前批次、产品和风险状态快速建立审核上下文。

+ +
+ +
+

推荐提问模板

+

用这些提问模板快速进入目录汇总、完整性检查、字段抽取和风险分析。

+
+ {% for item in prompt_templates %} + {{ item }} + {% endfor %} +
+
+
+ {% endif %} +
diff --git a/tests/test_chat.py b/tests/test_chat.py index ca072c9..99c3547 100644 --- a/tests/test_chat.py +++ b/tests/test_chat.py @@ -376,6 +376,36 @@ def test_chat_page_shows_upload_entry_and_dynamic_context_cards(client, db): assert "飞书通知 / 待处理" in content +def test_chat_page_shows_top_context_and_recommended_prompts(client, db): + batch, conversation = _create_conversation_with_batch() + conversation.task_status = "processing" + conversation.node_results = [ + {"label": "资料包导入", "status": "已完成"}, + {"label": "目录汇总", "status": "已完成"}, + {"label": "法规完整性检查", "status": "已完成"}, + {"label": "字段抽取", "status": "已完成"}, + {"label": "一致性核查", "status": "待复核"}, + {"label": "风险预警", "status": "已阻断"}, + {"label": "Word 回填导出", "status": "待复核"}, + {"label": "飞书通知", "status": "待处理"}, + ] + conversation.save(update_fields=["task_status", "node_results", "updated_at"]) + + response = client.get(reverse("chat:detail", args=[conversation.conversation_id])) + + content = response.content.decode("utf-8") + assert response.status_code == 200 + assert "顶部对话上下文" in content + assert "当前流程类型" in content + assert "registration" in content + assert "当前审核阶段" in content + assert "processing" in content + assert "当前最高风险等级" in content + assert "推荐提问模板" in content + assert "请汇总当前资料包的章节点、页数和目录覆盖情况" in content + assert "请给出当前资料包的高风险项、责任人和整改建议" in content + + def test_chat_page_blocks_formal_export_when_word_export_node_is_blocked(client, db): batch, conversation = _create_conversation_with_batch() conversation.node_results = [