From 71763684a9eba3dfbac632600402927d61d222ba Mon Sep 17 00:00:00 2001 From: Debanjum Date: Wed, 11 Jun 2025 12:39:39 -0700 Subject: [PATCH] Explicitly drop stream_options if not streaming openai chat response Not sure why but it some cases when interacting with o3 (which needs non-streaming) the stream_options seems to be set. Cannot reproduce but hopefully dropping the stream_options explicitly should resolve this issue. Related 985a98214 --- 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 20e632d0..253cdc25 100644 --- a/src/khoj/processor/conversation/openai/utils.py +++ b/src/khoj/processor/conversation/openai/utils.py @@ -201,6 +201,8 @@ async def chat_completion_with_backoff( stream_processor = adefault_stream_processor if stream: model_kwargs["stream_options"] = {"include_usage": True} + else: + model_kwargs.pop("stream_options", None) formatted_messages = format_message_for_api(messages, api_base_url)