From eaae1cf74efa5e625e273577e9123f9ddb2b66bf Mon Sep 17 00:00:00 2001 From: Debanjum Date: Wed, 11 Jun 2025 13:09:38 -0700 Subject: [PATCH] Fix rendering thoughts of Gemini reasoning models Previously there was duplication of thought in message to user and in the train of thought. This should be resolved now --- src/khoj/processor/conversation/google/utils.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/khoj/processor/conversation/google/utils.py b/src/khoj/processor/conversation/google/utils.py index 92760e65..f397bf52 100644 --- a/src/khoj/processor/conversation/google/utils.py +++ b/src/khoj/processor/conversation/google/utils.py @@ -239,12 +239,11 @@ async def gemini_chat_completion_with_backoff( # emit thought vs response parts for part in chunk.candidates[0].content.parts: - if part.text: - aggregated_response += part.text - yield ResponseWithThought(response=part.text) if part.thought: yield ResponseWithThought(thought=part.text) - + elif part.text: + aggregated_response += part.text + yield ResponseWithThought(response=part.text) # Calculate cost of chat input_tokens = final_chunk.usage_metadata.prompt_token_count or 0 if final_chunk else 0 output_tokens = final_chunk.usage_metadata.candidates_token_count or 0 if final_chunk else 0