File tree Expand file tree Collapse file tree 2 files changed +5
-4
lines changed Expand file tree Collapse file tree 2 files changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ def build_search_function() -> list[ChatCompletionToolParam]:
1818 "properties" : {
1919 "search_query" : {
2020 "type" : "string" ,
21- "description" : "Query string to use for full text search, e.g. 'red shoes'" ,
21+ "description" : "Query string to use for full text search, e.g. 'red shoes'. This required parameter must always be specified. " ,
2222 },
2323 "price_filter" : {
2424 "type" : "object" ,
@@ -56,7 +56,7 @@ def build_search_function() -> list[ChatCompletionToolParam]:
5656 ]
5757
5858
59- def extract_search_arguments (chat_completion : ChatCompletion ):
59+ def extract_search_arguments (original_user_query : str , chat_completion : ChatCompletion ):
6060 response_message = chat_completion .choices [0 ].message
6161 search_query = None
6262 filters = []
@@ -67,7 +67,8 @@ def extract_search_arguments(chat_completion: ChatCompletion):
6767 function = tool .function
6868 if function .name == "search_database" :
6969 arg = json .loads (function .arguments )
70- search_query = arg .get ("search_query" )
70+ # Even though its required, search_query is not always specified
71+ search_query = arg .get ("search_query" , original_user_query )
7172 if "price_filter" in arg and arg ["price_filter" ]:
7273 price_filter = arg ["price_filter" ]
7374 filters .append (
Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ async def run(
6565 tool_choice = "auto" ,
6666 )
6767
68- query_text , filters = extract_search_arguments (chat_completion )
68+ query_text , filters = extract_search_arguments (original_user_query , chat_completion )
6969
7070 # Retrieve relevant items from the database with the GPT optimized query
7171 results = await self .searcher .search_and_embed (
You can’t perform that action at this time.
0 commit comments