Add errors to search (#2854)

* minor - add errors to search

* k
This commit is contained in:
pablodanswer
2024-10-19 12:11:46 -07:00
committed by GitHub
parent f7d77a3c76
commit 2c77ad2aab
2 changed files with 16 additions and 12 deletions

View File

@@ -1,3 +1,5 @@
import json
from collections.abc import Generator
from uuid import UUID from uuid import UUID
from fastapi import APIRouter from fastapi import APIRouter
@@ -267,10 +269,17 @@ def get_answer_with_quote(
logger.notice(f"Received query for one shot answer with quotes: {query}") logger.notice(f"Received query for one shot answer with quotes: {query}")
packets = stream_search_answer( def stream_generator() -> Generator[str, None, None]:
try:
for packet in stream_search_answer(
query_req=query_request, query_req=query_request,
user=user, user=user,
max_document_tokens=None, max_document_tokens=None,
max_history_tokens=0, max_history_tokens=0,
) ):
return StreamingResponse(packets, media_type="application/json") yield json.dumps(packet) if isinstance(packet, dict) else packet
except Exception as e:
logger.exception(f"Error in search answer streaming: {e}")
yield json.dumps({"error": str(e)})
return StreamingResponse(stream_generator(), media_type="application/json")

View File

@@ -59,11 +59,6 @@ const SEARCH_DEFAULT_OVERRIDES_START: SearchDefaultOverrides = {
offset: 0, offset: 0,
}; };
const VALID_QUESTION_RESPONSE_DEFAULT: ValidQuestionResponse = {
reasoning: null,
error: null,
};
interface SearchSectionProps { interface SearchSectionProps {
toggle: () => void; toggle: () => void;
defaultSearchType: SearchType; defaultSearchType: SearchType;