@@ -52,6 +52,9 @@ class BrandFilter(TypedDict):
52
52
53
53
54
54
class SearchResults (TypedDict ):
55
+ query : str
56
+ """The original search query"""
57
+
55
58
items : list [ItemPublic ]
56
59
"""List of items that match the search query and filters"""
57
60
@@ -105,7 +108,9 @@ async def search_database(
105
108
enable_text_search = ctx .deps .enable_text_search ,
106
109
filters = filters ,
107
110
)
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
+ )
109
114
110
115
async def prepare_context (self , chat_params : ChatParams ) -> tuple [list [ItemPublic ], list [ThoughtStep ]]:
111
116
model = OpenAIModel (
@@ -119,35 +124,36 @@ async def prepare_context(self, chat_params: ChatParams) -> tuple[list[ItemPubli
119
124
output_type = SearchResults ,
120
125
)
121
126
# TODO: Provide few-shot examples
127
+ user_query = f"Find search results for user query: { chat_params .original_user_query } "
122
128
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 ,
125
131
deps = chat_params ,
126
132
)
127
- items = results .output . items
133
+ items = results .output [ " items" ]
128
134
thoughts = [
129
135
ThoughtStep (
130
136
title = "Prompt to generate search arguments" ,
131
- description = chat_params . past_messages , # TODO: update this
137
+ description = results . all_messages (),
132
138
props = (
133
139
{"model" : self .chat_model , "deployment" : self .chat_deployment }
134
140
if self .chat_deployment
135
- else {"model" : self .chat_model }
141
+ else {"model" : self .chat_model } # TODO
136
142
),
137
143
),
138
144
ThoughtStep (
139
145
title = "Search using generated search arguments" ,
140
- description = chat_params . original_user_query , # TODO:
146
+ description = results . output [ "query" ],
141
147
props = {
142
148
"top" : chat_params .top ,
143
149
"vector_search" : chat_params .enable_vector_search ,
144
150
"text_search" : chat_params .enable_text_search ,
145
- "filters" : [], # TODO
151
+ "filters" : results . output [ "filters" ],
146
152
},
147
153
),
148
154
ThoughtStep (
149
155
title = "Search results" ,
150
- description = "" , # TODO
156
+ description = items ,
151
157
),
152
158
]
153
159
return items , thoughts
@@ -178,12 +184,12 @@ async def answer(
178
184
return RetrievalResponse (
179
185
message = Message (content = str (response .output ), role = AIChatRoles .ASSISTANT ),
180
186
context = RAGContext (
181
- data_points = {}, # TODO
187
+ data_points = {item . id : item for item in items },
182
188
thoughts = earlier_thoughts
183
189
+ [
184
190
ThoughtStep (
185
191
title = "Prompt to generate answer" ,
186
- description = "" , # TODO: update
192
+ description = response . all_messages (),
187
193
props = (
188
194
{"model" : self .chat_model , "deployment" : self .chat_deployment }
189
195
if self .chat_deployment
0 commit comments