Skip to content

Commit 4c3d32e

Browse files
committed
fix:补全注释及ruff
1 parent 040915c commit 4c3d32e

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

astrbot/core/agent/runners/tool_loop_agent_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

astrbot/core/provider/sources/openai_source.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff 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:

0 commit comments

Comments
 (0)