From d55cba8627f56f950c3ed2b49f48a7f4f02cb706 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Sat, 19 Oct 2024 14:05:21 -0700 Subject: [PATCH] Pass user query for chat response when document lookup fails Recent changes made Khoj try respond even when document lookup fails. This change missed handling downstream effects of a failed document lookup, as the defiltered_query was null and so the text response didn't have the user query to respond to. This code initializes defiltered_query to original user query to handle that. Also response_type wasn't being passed via send_message_to_model_wrapper_sync unlike in the async scenario --- src/khoj/routers/api_chat.py | 7 +++---- src/khoj/routers/helpers.py | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/khoj/routers/api_chat.py b/src/khoj/routers/api_chat.py index 0d367029..d57b5530 100644 --- a/src/khoj/routers/api_chat.py +++ b/src/khoj/routers/api_chat.py @@ -10,9 +10,8 @@ from urllib.parse import unquote from asgiref.sync import sync_to_async from fastapi import APIRouter, Depends, HTTPException, Request -from fastapi.requests import Request from fastapi.responses import Response, StreamingResponse -from starlette.authentication import has_required_scope, requires +from starlette.authentication import requires from khoj.app.settings import ALLOWED_HOSTS from khoj.database.adapters import ( @@ -837,7 +836,7 @@ async def chat( # Gather Context ## Extract Document References - compiled_references, inferred_queries, defiltered_query = [], [], None + compiled_references, inferred_queries, defiltered_query = [], [], q try: async for result in extract_references_and_questions( request, @@ -960,7 +959,7 @@ async def chat( ## Generate Image Output if ConversationCommand.Image in conversation_commands: async for result in text_to_image( - q, + defiltered_query, user, meta_log, location_data=location, diff --git a/src/khoj/routers/helpers.py b/src/khoj/routers/helpers.py index c3d997e9..12616e36 100644 --- a/src/khoj/routers/helpers.py +++ b/src/khoj/routers/helpers.py @@ -881,6 +881,7 @@ def send_message_to_model_wrapper_sync( messages=truncated_messages, api_key=api_key, model=chat_model, + response_type=response_type, ) else: raise HTTPException(status_code=500, detail="Invalid conversation config")