File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -257,7 +257,7 @@ async def _iter_llm_responses_with_fallback(
257257 candidate_id ,
258258 )
259259 break
260-
260+
261261 yield resp
262262 return
263263
Original file line number Diff line number Diff line change @@ -307,12 +307,15 @@ async def _query_stream(
307307 state = ChatCompletionStreamState ()
308308
309309 async for chunk in stream :
310- # 兼容非标准返回处理 补全tool_call.type字段
310+ # 兼容处理:部分非标准聚合平台(如通过newapi适配层转接的 Gemini)在流式返回 tool_calls 时,
311+ # 可能会缺失 type 字段。由于 openai SDK 的 ChatCompletionStreamState.handle_chunk
312+ # 内部有 assert tool.type == "function" 的断言,缺少该字段会导致 AssertionError。
313+ # 因此,若检测到 tool_call 且 type 为空,在此处手动补全为 "function"。
311314 for choice in chunk .choices or []:
312315 if not choice .delta or not choice .delta .tool_calls :
313316 continue
314317 for tool_call in choice .delta .tool_calls :
315- if tool_call .type is None :
318+ if hasattr ( tool_call , "type" ) and tool_call .type is None :
316319 tool_call .type = "function"
317320
318321 try :
You can’t perform that action at this time.
0 commit comments