From 9d675d2a463fc15c681b75de4995f02d7526a514 Mon Sep 17 00:00:00 2001 From: kx_guo Date: Wed, 28 Oct 2026 17:00:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=AC=AC=E4=B8=89=E6=96=B9?= =?UTF-8?q?=E6=8A=A5=E5=91=8A=E8=BF=BD=E9=97=AE=E4=BA=8B=E5=8A=A1=E5=92=8C?= =?UTF-8?q?=E4=B8=8A=E4=B8=8B=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/conversations.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/services/conversations.py b/app/services/conversations.py index 8e06e18..bb95f9c 100644 --- a/app/services/conversations.py +++ b/app/services/conversations.py @@ -308,6 +308,11 @@ class ConversationService: yield {"type": "error", "message": "LLM 未返回有效内容"} return + if persist_reply is not None: + assistant_message = await persist_reply(reply, semantics) + yield {"type": "done", "data": {"assistantMessageId": assistant_message.id}} + return + # Persist the complete assistant text before optional card enrichment. # A slow or failed RAG/score lookup must not lose the conversation turn. assistant_message = ConversationMessage( @@ -378,6 +383,8 @@ class ConversationService: conversation: Conversation, current_text: str, semantics: dict[str, Any], + *, + external_context: str | None = None, ) -> Sequence[dict[str, str]]: messages = reply_system_messages(semantics) messages.append( @@ -390,6 +397,8 @@ class ConversationService: structured_context = ConversationService._structured_context(conversation, summary=is_summary) if structured_context: messages.append({"role": "system", "content": structured_context}) + if external_context: + messages.append({"role": "system", "content": external_context}) if is_summary: messages.append( {