From e635b8e3b98e8dbf0e87f43d61b48b847327e485 Mon Sep 17 00:00:00 2001 From: Debanjum Date: Fri, 13 Jun 2025 14:49:54 -0700 Subject: [PATCH] Handle gemini chat response completion chunk when streaming --- src/khoj/processor/conversation/google/utils.py | 2 +- src/khoj/routers/api_chat.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/khoj/processor/conversation/google/utils.py b/src/khoj/processor/conversation/google/utils.py index f397bf52..acda998d 100644 --- a/src/khoj/processor/conversation/google/utils.py +++ b/src/khoj/processor/conversation/google/utils.py @@ -238,7 +238,7 @@ async def gemini_chat_completion_with_backoff( break # emit thought vs response parts - for part in chunk.candidates[0].content.parts: + for part in chunk.candidates[0].content.parts or []: if part.thought: yield ResponseWithThought(thought=part.text) elif part.text: diff --git a/src/khoj/routers/api_chat.py b/src/khoj/routers/api_chat.py index da52746a..8091a13d 100644 --- a/src/khoj/routers/api_chat.py +++ b/src/khoj/routers/api_chat.py @@ -1057,7 +1057,7 @@ async def chat( # researched_results = await extract_relevant_info(q, researched_results, agent) if state.verbose > 1: - logger.debug(f'Researched Results: {"".join(r.summarizedResult for r in research_results)}') + logger.debug(f'Researched Results: {"".join(r.summarizedResult or "" for r in research_results)}') # Gather Context ## Extract Document References