Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions astrbot/core/provider/sources/openai_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,14 @@ async def _query_stream(
state = ChatCompletionStreamState()

async for chunk in stream:
# Fix for #6661: Add missing 'index' field to tool_call deltas
# Gemini and some OpenAI-compatible proxies omit this field
if chunk.choices:
for choice in chunk.choices:
if choice.delta and choice.delta.tool_calls:
for idx, tc in enumerate(choice.delta.tool_calls):
if not hasattr(tc, "index") or tc.index is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For improved readability and maintainability, consider using getattr with a default value to check for the missing or None index. This is a more concise and idiomatic Python pattern for this type of check.

Suggested change
if not hasattr(tc, "index") or tc.index is None:
if getattr(tc, "index", None) is None:

tc.index = idx
try:
state.handle_chunk(chunk)
except Exception as e:
Expand Down