1616from openai .types .responses import EasyInputMessageParam , ResponseInputItemParam , ResponseTextDeltaEvent
1717
1818from fastapi_app .api_models import (
19- AIChatRoles ,
2019 BrandFilter ,
2120 ChatRequestOverrides ,
2221 Filter ,
2322 ItemPublic ,
24- Message ,
2523 PriceFilter ,
2624 RAGContext ,
2725 RetrievalResponse ,
@@ -124,7 +122,7 @@ async def prepare_context(self) -> tuple[list[ItemPublic], list[ThoughtStep]]:
124122 thoughts = [
125123 ThoughtStep (
126124 title = "Prompt to generate search arguments" ,
127- description = [{"content" : self .query_prompt_template }]
125+ description = [{"role" : "system" , " content" : self .query_prompt_template }]
128126 + ItemHelpers .input_to_new_input_list (run_results .input ),
129127 props = self .model_for_thoughts ,
130128 ),
@@ -157,14 +155,14 @@ async def answer(
157155 )
158156
159157 return RetrievalResponse (
160- message = Message ( content = str (run_results .final_output ), role = AIChatRoles . ASSISTANT ),
158+ output_text = str (run_results .final_output ),
161159 context = RAGContext (
162160 data_points = {item .id : item for item in items },
163161 thoughts = earlier_thoughts
164162 + [
165163 ThoughtStep (
166164 title = "Prompt to generate answer" ,
167- description = [{"content" : self .answer_prompt_template }]
165+ description = [{"role" : "system" , " content" : self .answer_prompt_template }]
168166 + ItemHelpers .input_to_new_input_list (run_results .input ),
169167 props = self .model_for_thoughts ,
170168 ),
@@ -184,13 +182,14 @@ async def answer_stream(
184182 )
185183
186184 yield RetrievalResponseDelta (
185+ type = "response.context" ,
187186 context = RAGContext (
188187 data_points = {item .id : item for item in items },
189188 thoughts = earlier_thoughts
190189 + [
191190 ThoughtStep (
192191 title = "Prompt to generate answer" ,
193- description = [{"content" : self .answer_prompt_template }]
192+ description = [{"role" : "system" , " content" : self .answer_prompt_template }]
194193 + ItemHelpers .input_to_new_input_list (run_results .input ),
195194 props = self .model_for_thoughts ,
196195 ),
@@ -200,5 +199,5 @@ async def answer_stream(
200199
201200 async for event in run_results .stream_events ():
202201 if event .type == "raw_response_event" and isinstance (event .data , ResponseTextDeltaEvent ):
203- yield RetrievalResponseDelta (delta = Message ( content = str (event .data .delta ), role = AIChatRoles . ASSISTANT ))
202+ yield RetrievalResponseDelta (type = "response.output_text. delta" , delta = str (event .data .delta ))
204203 return
0 commit comments