@@ -52,6 +52,9 @@ class BrandFilter(TypedDict):
5252
5353
5454class SearchResults (TypedDict ):
55+ query : str
56+ """The original search query"""
57+
5558 items : list [ItemPublic ]
5659 """List of items that match the search query and filters"""
5760
@@ -105,7 +108,9 @@ async def search_database(
105108 enable_text_search = ctx .deps .enable_text_search ,
106109 filters = filters ,
107110 )
108- return SearchResults (items = [ItemPublic .model_validate (item .to_dict ()) for item in results ], filters = filters )
111+ return SearchResults (
112+ query = search_query , items = [ItemPublic .model_validate (item .to_dict ()) for item in results ], filters = filters
113+ )
109114
110115 async def prepare_context (self , chat_params : ChatParams ) -> tuple [list [ItemPublic ], list [ThoughtStep ]]:
111116 model = OpenAIModel (
@@ -119,35 +124,36 @@ async def prepare_context(self, chat_params: ChatParams) -> tuple[list[ItemPubli
119124 output_type = SearchResults ,
120125 )
121126 # TODO: Provide few-shot examples
127+ user_query = f"Find search results for user query: { chat_params .original_user_query } "
122128 results = await agent .run (
123- f"Find search results for user query: { chat_params . original_user_query } " ,
124- # message_history=chat_params.past_messages, # TODO
129+ user_query ,
130+ message_history = chat_params .past_messages ,
125131 deps = chat_params ,
126132 )
127- items = results .output . items
133+ items = results .output [ " items" ]
128134 thoughts = [
129135 ThoughtStep (
130136 title = "Prompt to generate search arguments" ,
131- description = chat_params . past_messages , # TODO: update this
137+ description = results . all_messages (),
132138 props = (
133139 {"model" : self .chat_model , "deployment" : self .chat_deployment }
134140 if self .chat_deployment
135- else {"model" : self .chat_model }
141+ else {"model" : self .chat_model } # TODO
136142 ),
137143 ),
138144 ThoughtStep (
139145 title = "Search using generated search arguments" ,
140- description = chat_params . original_user_query , # TODO:
146+ description = results . output [ "query" ],
141147 props = {
142148 "top" : chat_params .top ,
143149 "vector_search" : chat_params .enable_vector_search ,
144150 "text_search" : chat_params .enable_text_search ,
145- "filters" : [], # TODO
151+ "filters" : results . output [ "filters" ],
146152 },
147153 ),
148154 ThoughtStep (
149155 title = "Search results" ,
150- description = "" , # TODO
156+ description = items ,
151157 ),
152158 ]
153159 return items , thoughts
@@ -178,12 +184,12 @@ async def answer(
178184 return RetrievalResponse (
179185 message = Message (content = str (response .output ), role = AIChatRoles .ASSISTANT ),
180186 context = RAGContext (
181- data_points = {}, # TODO
187+ data_points = {item . id : item for item in items },
182188 thoughts = earlier_thoughts
183189 + [
184190 ThoughtStep (
185191 title = "Prompt to generate answer" ,
186- description = "" , # TODO: update
192+ description = response . all_messages (),
187193 props = (
188194 {"model" : self .chat_model , "deployment" : self .chat_deployment }
189195 if self .chat_deployment
0 commit comments