Extract thought stream from reasoning_content of openai model providers

Grok 3 mini at least sends thoughts in reasoning_content field of
streamed chunk delta. Extract model thoughts from that when available.
This commit is contained in:
Debanjum
2025-07-31 16:00:59 -07:00
parent b335f8cf79
commit fba4ad27f7

View File

@@ -147,6 +147,12 @@ def completion_with_backoff(
aggregated_response += chunk.delta
elif chunk.type == "thought.delta":
thoughts += chunk.delta
elif (
chunk.type == "chunk"
and chunk.chunk.choices
and hasattr(chunk.chunk.choices[0].delta, "reasoning_content")
):
thoughts += chunk.chunk.choices[0].delta.reasoning_content
elif chunk.type == "chunk" and chunk.chunk.choices and chunk.chunk.choices[0].delta.tool_calls:
tool_ids += [tool_call.id for tool_call in chunk.chunk.choices[0].delta.tool_calls]
elif chunk.type == "tool_calls.function.arguments.done":