Skip to content

Workaround for older model that doesnt specify required param #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/fastapi_app/query_rewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def build_search_function() -> list[ChatCompletionToolParam]:
]


def extract_search_arguments(chat_completion: ChatCompletion):
def extract_search_arguments(original_user_query: str, chat_completion: ChatCompletion):
response_message = chat_completion.choices[0].message
search_query = None
filters = []
Expand All @@ -67,7 +67,8 @@ def extract_search_arguments(chat_completion: ChatCompletion):
function = tool.function
if function.name == "search_database":
arg = json.loads(function.arguments)
search_query = arg.get("search_query")
# Even though its required, search_query is not always specified
search_query = arg.get("search_query", original_user_query)
if "price_filter" in arg and arg["price_filter"]:
price_filter = arg["price_filter"]
filters.append(
Expand Down
2 changes: 1 addition & 1 deletion src/fastapi_app/rag_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async def run(
tool_choice="auto",
)

query_text, filters = extract_search_arguments(chat_completion)
query_text, filters = extract_search_arguments(original_user_query, chat_completion)

# Retrieve relevant items from the database with the GPT optimized query
results = await self.searcher.search_and_embed(
Expand Down
Loading