Skip to content

Commit

Permalink
Use nonlocal for conversation_id when running the event_generator
Browse files Browse the repository at this point in the history
  • Loading branch information
sabaimran committed Sep 3, 2024
1 parent 591f5a5 commit 912cc00
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/khoj/routers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/khoj/routers/api_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 912cc00

Please sign in to comment.