fix(regulatory): 自动执行法规核查前置汇总

This commit is contained in:
2026-06-07 12:17:20 +08:00
parent 911e5378e8
commit 1b4a10b5ba
4 changed files with 110 additions and 14 deletions

View File

@@ -10,7 +10,7 @@ from django.utils import timezone
from .file_summary.skills.attachment_reader import AttachmentReaderSkill
from .file_summary.workflow import create_file_summary_batch, start_file_summary_workflow
from .llm import LLMConfigurationError, LLMRequestError, generate_reply, stream_reply
from .models import Conversation, FileAttachment, Message
from .models import Conversation, FileAttachment, FileSummaryBatch, Message
from .regulatory_review.workflow import (
create_regulatory_review_batch,
find_latest_successful_summary_batch,
@@ -227,18 +227,51 @@ def stream_message(conversation: Conversation, content: str):
if route.starts_regulatory_review:
source_summary_batch = find_latest_successful_summary_batch(conversation)
if not source_summary_batch:
reply_content = "请先执行自动汇总,生成成功的文件汇总批次后再启动法规核查。"
assistant_message = append_assistant_message(conversation, reply_content)
yield sse_event("chunk", {"delta": reply_content})
if not _has_active_attachments(conversation):
reply_content = "请先在当前对话右侧上传需要核查的文件或压缩包,我会先自动汇总再继续法规核查。"
assistant_message = append_assistant_message(conversation, reply_content)
yield sse_event("chunk", {"delta": reply_content})
yield sse_event(
"done",
{
"assistant_message_id": assistant_message.pk,
"conversation_id": conversation.pk,
"title": conversation.title,
},
)
return
summary_batch = create_file_summary_batch(
conversation=conversation,
user=conversation.user,
trigger_message=user_message,
)
yield sse_event(
"done",
"workflow_started",
{
"assistant_message_id": assistant_message.pk,
"conversation_id": conversation.pk,
"title": conversation.title,
"workflow_type": "file_summary",
"batch_id": summary_batch.pk,
"batch_no": summary_batch.batch_no,
},
)
return
start_file_summary_workflow(summary_batch, async_run=False)
summary_batch.refresh_from_db()
if summary_batch.status != FileSummaryBatch.Status.SUCCESS:
reply_content = f"已先启动文件目录与页数自动汇总工作流,批次号:{summary_batch.batch_no},但汇总未成功:{summary_batch.error_message or '原因待查看'}。请处理后再启动法规核查。"
assistant_message = append_assistant_message(conversation, reply_content)
yield sse_event("chunk", {"delta": reply_content})
yield sse_event(
"done",
{
"assistant_message_id": assistant_message.pk,
"conversation_id": conversation.pk,
"title": conversation.title,
},
)
return
source_summary_batch = summary_batch
reply_prefix = f"已先启动文件目录与页数自动汇总工作流,批次号:{summary_batch.batch_no},汇总完成后继续法规核查。\n"
else:
reply_prefix = ""
batch = create_regulatory_review_batch(
conversation=conversation,
user=conversation.user,
@@ -249,7 +282,7 @@ def stream_message(conversation: Conversation, content: str):
batch,
async_run=getattr(settings, "REGULATORY_REVIEW_ASYNC", True),
)
reply_content = f"已启动 NMPA 注册资料法规核查工作流,批次号:{batch.batch_no}"
reply_content = f"{reply_prefix}已启动 NMPA 注册资料法规核查工作流,批次号:{batch.batch_no}"
assistant_message = append_assistant_message(conversation, reply_content)
yield sse_event(
"workflow_started",