mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-07 21:29:13 +00:00
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
This commit is contained in:
@@ -10,9 +10,8 @@ from urllib.parse import unquote
|
|||||||
|
|
||||||
from asgiref.sync import sync_to_async
|
from asgiref.sync import sync_to_async
|
||||||
from fastapi import APIRouter, Depends, HTTPException, Request
|
from fastapi import APIRouter, Depends, HTTPException, Request
|
||||||
from fastapi.requests import Request
|
|
||||||
from fastapi.responses import Response, StreamingResponse
|
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.app.settings import ALLOWED_HOSTS
|
||||||
from khoj.database.adapters import (
|
from khoj.database.adapters import (
|
||||||
@@ -837,7 +836,7 @@ async def chat(
|
|||||||
|
|
||||||
# Gather Context
|
# Gather Context
|
||||||
## Extract Document References
|
## Extract Document References
|
||||||
compiled_references, inferred_queries, defiltered_query = [], [], None
|
compiled_references, inferred_queries, defiltered_query = [], [], q
|
||||||
try:
|
try:
|
||||||
async for result in extract_references_and_questions(
|
async for result in extract_references_and_questions(
|
||||||
request,
|
request,
|
||||||
@@ -960,7 +959,7 @@ async def chat(
|
|||||||
## Generate Image Output
|
## Generate Image Output
|
||||||
if ConversationCommand.Image in conversation_commands:
|
if ConversationCommand.Image in conversation_commands:
|
||||||
async for result in text_to_image(
|
async for result in text_to_image(
|
||||||
q,
|
defiltered_query,
|
||||||
user,
|
user,
|
||||||
meta_log,
|
meta_log,
|
||||||
location_data=location,
|
location_data=location,
|
||||||
|
|||||||
@@ -881,6 +881,7 @@ def send_message_to_model_wrapper_sync(
|
|||||||
messages=truncated_messages,
|
messages=truncated_messages,
|
||||||
api_key=api_key,
|
api_key=api_key,
|
||||||
model=chat_model,
|
model=chat_model,
|
||||||
|
response_type=response_type,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise HTTPException(status_code=500, detail="Invalid conversation config")
|
raise HTTPException(status_code=500, detail="Invalid conversation config")
|
||||||
|
|||||||
Reference in New Issue
Block a user