From e968cca2735d91bae62aabf65bfe58b8ba8cf19e Mon Sep 17 00:00:00 2001 From: Debanjum Date: Fri, 23 May 2025 14:34:55 -0700 Subject: [PATCH] Clean usage of conversation_id in chat API function - Normalize conversation_id type to str instead of str or UUID - Do not pass conversation_id to agenerate_chat_response as the associated conversation is also being passed. So can get its id directly. --- src/khoj/routers/api_chat.py | 5 ++--- src/khoj/routers/helpers.py | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/khoj/routers/api_chat.py b/src/khoj/routers/api_chat.py index 8f4d9f31..fed6a559 100644 --- a/src/khoj/routers/api_chat.py +++ b/src/khoj/routers/api_chat.py @@ -860,9 +860,9 @@ async def chat( async for result in send_llm_response(f"Conversation {conversation_id} not found", tracer.get("usage")): yield result return - conversation_id = conversation.id + conversation_id = str(conversation.id) - async for event in send_event(ChatEvent.METADATA, {"conversationId": str(conversation_id), "turnId": turn_id}): + async for event in send_event(ChatEvent.METADATA, {"conversationId": conversation_id, "turnId": turn_id}): yield event agent: Agent | None = None @@ -1383,7 +1383,6 @@ async def chat( conversation_commands, user, request.user.client_app, - conversation_id, location, user_name, researched_results, diff --git a/src/khoj/routers/helpers.py b/src/khoj/routers/helpers.py index b5c489b4..38cf9174 100644 --- a/src/khoj/routers/helpers.py +++ b/src/khoj/routers/helpers.py @@ -1359,7 +1359,6 @@ async def agenerate_chat_response( conversation_commands: List[ConversationCommand] = [ConversationCommand.Default], user: KhojUser = None, client_application: ClientApplication = None, - conversation_id: str = None, location_data: LocationData = None, user_name: Optional[str] = None, meta_research: str = "", @@ -1394,7 +1393,7 @@ async def agenerate_chat_response( operator_results=operator_results, inferred_queries=inferred_queries, client_application=client_application, - conversation_id=conversation_id, + conversation_id=str(conversation.id), query_images=query_images, train_of_thought=train_of_thought, raw_query_files=raw_query_files,