From 912cc0074a55b9d4284afa681e067667fda776a8 Mon Sep 17 00:00:00 2001 From: sabaimran Date: Tue, 3 Sep 2024 11:55:06 -0700 Subject: [PATCH] Use nonlocal for conversation_id when running the event_generator --- src/khoj/routers/api.py | 2 +- src/khoj/routers/api_chat.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/khoj/routers/api.py b/src/khoj/routers/api.py index 5fc79bcd0..40c65ce21 100644 --- a/src/khoj/routers/api.py +++ b/src/khoj/routers/api.py @@ -358,7 +358,7 @@ async def extract_references_and_questions( conversation = await sync_to_async(ConversationAdapters.get_conversation_by_id)(conversation_id) if not conversation: - logger.error(f"Conversation with id {conversation_id} not found.") + logger.error(f"Conversation with id {conversation_id} not found when extracting references.") yield compiled_references, inferred_queries, defiltered_query return diff --git a/src/khoj/routers/api_chat.py b/src/khoj/routers/api_chat.py index 39c1e48bf..7fb483470 100644 --- a/src/khoj/routers/api_chat.py +++ b/src/khoj/routers/api_chat.py @@ -548,6 +548,7 @@ async def event_generator(q: str): subscribed: bool = has_required_scope(request, ["premium"]) event_delimiter = "␃🔚␗" q = unquote(q) + nonlocal conversation_id async def send_event(event_type: ChatEvent, data: str | dict): nonlocal connection_alive, ttft @@ -615,6 +616,7 @@ def collect_telemetry(): async for result in send_llm_response(f"Conversation {conversation_id} not found"): yield result return + conversation_id = conversation.id await is_ready_to_chat(user)