From f6ce2fd432532d6c56035ddb3cd8e1f5acbec8f0 Mon Sep 17 00:00:00 2001 From: sabaimran Date: Tue, 20 Aug 2024 10:50:09 -0700 Subject: [PATCH] Handle end of chunk logic in openai stream processor --- src/khoj/processor/conversation/openai/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/khoj/processor/conversation/openai/utils.py b/src/khoj/processor/conversation/openai/utils.py index 314c3c1d..f910b50c 100644 --- a/src/khoj/processor/conversation/openai/utils.py +++ b/src/khoj/processor/conversation/openai/utils.py @@ -56,6 +56,8 @@ def completion_with_backoff( ) aggregated_response = "" for chunk in chat: + if len(chunk.choices) == 0: + continue delta_chunk = chunk.choices[0].delta # type: ignore if isinstance(delta_chunk, str): aggregated_response += delta_chunk