@@ -783,63 +783,47 @@ async def response_generator(
783783
784784 yield stream_end_event (context .metadata_map , summary , token_usage , media_type )
785785
786- # Perform cleanup tasks (database and cache operations)
787- await cleanup_after_streaming (
788- user_id = context .user_id ,
789- conversation_id = context .conversation_id ,
790- model_id = context .model_id ,
791- provider_id = context .provider_id ,
792- llama_stack_model_id = context .llama_stack_model_id ,
793- query_request = context .query_request ,
794- summary = summary ,
795- metadata_map = context .metadata_map ,
796- started_at = context .started_at ,
797- client = context .client ,
798- config = configuration ,
799- skip_userid_check = context .skip_userid_check ,
800- get_topic_summary_func = get_topic_summary ,
801- is_transcripts_enabled_func = is_transcripts_enabled ,
802- store_transcript_func = store_transcript ,
803- persist_user_conversation_details_func = persist_user_conversation_details ,
804- rag_chunks = create_rag_chunks_dict (summary ),
805- )
806-
807- return response_generator
808-
809-
810- async def streaming_query_endpoint_handler_base ( # pylint: disable=too-many-locals,too-many-statements,too-many-arguments,too-many-positional-arguments
811- request : Request ,
812- query_request : QueryRequest ,
813- auth : AuthTuple ,
814- mcp_headers : dict [str , dict [str , str ]],
815- retrieve_response_func : Callable [..., Any ],
816- create_response_generator_func : Callable [..., Any ],
817- ) -> StreamingResponse :
818- """
819- Handle streaming query endpoints with common logic.
820-
821- This base handler contains all the common logic for streaming query endpoints
822- and accepts functions for API-specific behavior (Agent API vs Responses API).
823-
824- Args:
825- request: The FastAPI request object
826- query_request: The query request from the user
827- auth: Authentication tuple (user_id, username, skip_check, token)
828- mcp_headers: MCP headers for tool integrations
829- retrieve_response_func: Function to retrieve the streaming response
830- create_response_generator_func: Function factory that creates the response generator
831-
832- Returns:
833- StreamingResponse: An HTTP streaming response yielding SSE-formatted events
834-
835- Raises:
836- HTTPException: Returns HTTP 500 if unable to connect to Llama Stack
837- """
838- # Nothing interesting in the request
839- _ = request
786+ if not is_transcripts_enabled ():
787+ logger .debug ("Transcript collection is disabled in the configuration" )
788+ else :
789+ store_transcript (
790+ user_id = user_id ,
791+ conversation_id = conversation_id ,
792+ model_id = model_id ,
793+ provider_id = provider_id ,
794+ query_is_valid = True , # TODO(lucasagomes): implement as part of query validation
795+ query = query_request .query ,
796+ query_request = query_request ,
797+ summary = summary ,
798+ rag_chunks = create_rag_chunks_dict (summary ),
799+ truncated = False , # TODO(lucasagomes): implement truncation as part
800+ # of quota work
801+ attachments = query_request .attachments or [],
802+ )
840803
841- check_configuration_loaded (configuration )
842- started_at = datetime .now (UTC ).strftime ("%Y-%m-%dT%H:%M:%SZ" )
804+ # Get the initial topic summary for the conversation
805+ topic_summary = None
806+ with get_session () as session :
807+ existing_conversation = (
808+ session .query (UserConversation )
809+ .filter_by (id = conversation_id )
810+ .first ()
811+ )
812+ if not existing_conversation :
813+ # Check if topic summary should be generated (default: True)
814+ should_generate = query_request .generate_topic_summary
815+ if should_generate :
816+ logger .debug ("Generating topic summary for new conversation" )
817+ topic_summary = await get_topic_summary (
818+ query_request .query , client , model_id
819+ )
820+ else :
821+ logger .debug (
822+ "Topic summary generation disabled by request parameter"
823+ )
824+ topic_summary = None
825+
826+ completed_at = datetime .now (UTC ).strftime ("%Y-%m-%dT%H:%M:%SZ" )
843827
844828 # Enforce RBAC: optionally disallow overriding model/provider in requests
845829 validate_model_provider_override (query_request , request .state .authorized_actions )
0 commit comments