diff --git a/backend/danswer/server/query_and_chat/query_backend.py b/backend/danswer/server/query_and_chat/query_backend.py index 703ef2c04..1b8d5dc4b 100644 --- a/backend/danswer/server/query_and_chat/query_backend.py +++ b/backend/danswer/server/query_and_chat/query_backend.py @@ -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") diff --git a/web/src/components/search/SearchSection.tsx b/web/src/components/search/SearchSection.tsx index b8c13be91..9f49e4715 100644 --- a/web/src/components/search/SearchSection.tsx +++ b/web/src/components/search/SearchSection.tsx @@ -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;