From fba4ad27f7fcd2db5b7c6dc020d963d8f181d5ed Mon Sep 17 00:00:00 2001 From: Debanjum Date: Thu, 31 Jul 2025 16:00:59 -0700 Subject: [PATCH] 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. --- src/khoj/processor/conversation/openai/utils.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/khoj/processor/conversation/openai/utils.py b/src/khoj/processor/conversation/openai/utils.py index 3b9e05a1..523786fc 100644 --- a/src/khoj/processor/conversation/openai/utils.py +++ b/src/khoj/processor/conversation/openai/utils.py @@ -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":