diff --git a/src/khoj/routers/api.py b/src/khoj/routers/api.py index f10543bd..4b22b1fa 100644 --- a/src/khoj/routers/api.py +++ b/src/khoj/routers/api.py @@ -277,15 +277,6 @@ def chat(q: Optional[str] = None, client: Optional[str] = None): status_code=500, detail="Chat processor not configured. Configure OpenAI API key on server and restart it." ) - # Initialize Variables - api_key = state.processor_config.conversation.openai_api_key - model = state.processor_config.conversation.model - chat_model = state.processor_config.conversation.chat_model - user_message_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S") - conversation_type = "general" if q.startswith("@general") else "notes" - compiled_references = [] - inferred_queries = [] - # Load Conversation History chat_session = state.processor_config.conversation.chat_session meta_log = state.processor_config.conversation.meta_log @@ -297,6 +288,15 @@ def chat(q: Optional[str] = None, client: Optional[str] = None): else: return {"status": "ok", "response": []} + # Initialize Variables + api_key = state.processor_config.conversation.openai_api_key + model = state.processor_config.conversation.model + chat_model = state.processor_config.conversation.chat_model + user_message_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S") + conversation_type = "general" if q.startswith("@general") else "notes" + compiled_references = [] + inferred_queries = [] + if conversation_type == "notes": # Infer search queries from user message with timer("Extracting search queries took", logger):