Skip to content

Commit 5c1569e

Browse files
committed
Workaround for older model
1 parent 730eeab commit 5c1569e

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/fastapi_app/query_rewriter.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff 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(

src/fastapi_app/rag_advanced.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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(

0 commit comments

Comments
 (0)