Skip to content

Commit

Permalink
Pass user query for chat response when document lookup fails
Browse files Browse the repository at this point in the history
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
  • Loading branch information
debanjum committed Oct 19, 2024
1 parent a4e6e1d commit d55cba8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/khoj/routers/api_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@

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 (
Expand Down Expand Up @@ -837,7 +836,7 @@ def collect_telemetry():

# 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,
Expand Down Expand Up @@ -960,7 +959,7 @@ def collect_telemetry():
## 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,
Expand Down
1 change: 1 addition & 0 deletions src/khoj/routers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit d55cba8

Please sign in to comment.