diff --git a/src/llm_models/model_client/openai_client.py b/src/llm_models/model_client/openai_client.py index 0b4f1e709..6902889c5 100644 --- a/src/llm_models/model_client/openai_client.py +++ b/src/llm_models/model_client/openai_client.py @@ -270,7 +270,15 @@ async def _default_stream_response_handler( # 如果中断量被设置,则抛出ReqAbortException _insure_buffer_closed() raise ReqAbortException("请求被外部信号中断") - + # 空 choices / usage-only 帧的防御 + if not getattr(event, "choices", None) or len(event.choices) == 0: + if getattr(event, "usage", None): + _usage_record = ( + event.usage.prompt_tokens or 0, + event.usage.completion_tokens or 0, + event.usage.total_tokens or 0, + ) + continue # 跳过本帧,避免访问 choices[0] delta = event.choices[0].delta # 获取当前块的delta内容 if hasattr(delta, "reasoning_content") and delta.reasoning_content: # type: ignore