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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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 fastapi import APIRouter
@ -267,10 +269,17 @@ def get_answer_with_quote(
logger.notice(f"Received query for one shot answer with quotes: {query}")
packets = stream_search_answer(
query_req=query_request,
user=user,
max_document_tokens=None,
max_history_tokens=0,
)
return StreamingResponse(packets, media_type="application/json")
def stream_generator() -> Generator[str, None, None]:
try:
for packet in stream_search_answer(
query_req=query_request,
user=user,
max_document_tokens=None,
max_history_tokens=0,
):
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,
};
const VALID_QUESTION_RESPONSE_DEFAULT: ValidQuestionResponse = {
reasoning: null,
error: null,
};
interface SearchSectionProps {
toggle: () => void;
defaultSearchType: SearchType;