From 43f349d415c5ec3896aa234da91bc0d0578ad1e6 Mon Sep 17 00:00:00 2001 From: fawney19 Date: Mon, 5 Jan 2026 09:36:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A1=AE=E4=BF=9D=20CLI=20handler=20?= =?UTF-8?q?=E7=9A=84=20streaming=20=E7=8A=B6=E6=80=81=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=97=B6=20provider=20=E4=BF=A1=E6=81=AF=E5=B7=B2=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在 execute_with_fallback 返回后,显式设置 ctx 的 provider 信息, 与 chat_handler_base.py 的行为保持一致,避免 streaming 状态更新 时 provider 为空的问题。 --- src/api/handlers/base/cli_handler_base.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/api/handlers/base/cli_handler_base.py b/src/api/handlers/base/cli_handler_base.py index a8d2778..f50c1de 100644 --- a/src/api/handlers/base/cli_handler_base.py +++ b/src/api/handlers/base/cli_handler_base.py @@ -329,9 +329,9 @@ class CliMessageHandlerBase(BaseMessageHandler): stream_generator, provider_name, attempt_id, - _provider_id, - _endpoint_id, - _key_id, + provider_id, + endpoint_id, + key_id, ) = await self.orchestrator.execute_with_fallback( api_format=ctx.api_format, model_name=ctx.model, @@ -341,7 +341,17 @@ class CliMessageHandlerBase(BaseMessageHandler): is_stream=True, capability_requirements=capability_requirements or None, ) + + # 更新上下文(确保 provider 信息已设置,用于 streaming 状态更新) ctx.attempt_id = attempt_id + if not ctx.provider_name: + ctx.provider_name = provider_name + if not ctx.provider_id: + ctx.provider_id = provider_id + if not ctx.endpoint_id: + ctx.endpoint_id = endpoint_id + if not ctx.key_id: + ctx.key_id = key_id # 创建后台任务记录统计 background_tasks = BackgroundTasks()