Skip to content

Commit

Permalink
only show rag result if database filters return empty list
Browse files Browse the repository at this point in the history
  • Loading branch information
Taniya-Das committed Aug 22, 2024
1 parent 9a8dab0 commit f740fbe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions frontend/ui_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def parse_and_update_response(self, metadata: pd.DataFrame):
print(self.structured_query_response) # Only for debugging. Comment later.
if self.structured_query_response[0] is not None and isinstance(self.structured_query_response[1], dict):
# Safely attempt to access the "filter" key in the first element
if self.structured_query_response[0].get("filter", None):
if self.structured_query_response[0].get("filter", None) and self.database_filtered:
filtered_metadata = metadata[
metadata["did"].isin(self.database_filtered)
]
Expand All @@ -297,7 +297,7 @@ def parse_and_update_response(self, metadata: pd.DataFrame):
filtered_metadata = metadata[
metadata["did"].isin(self.rag_response["initial_response"])
]
print("Showing only rag response as filter is empty")
print("Showing only rag response as filter is empty or none of the rag data satisfies filter conditions.")
filtered_metadata["did"] = pd.Categorical(
filtered_metadata["did"],
categories=self.rag_response["initial_response"],
Expand Down Expand Up @@ -414,7 +414,7 @@ def process_query_chat(self, query):
)

if response_parser.structured_query_response:
st.write("Detected Filter(s): ", json.dumps(response_parser.structured_query_response[0].get("filter", None)))
st.session_state.messages.append("Detected Filter(s): ", json.dumps(response_parser.structured_query_response[0].get("filter", None)))
else:
st.write("Detected Filter(s): ", None)
# st.write("Detected Topics: ", response_parser.structured_query_response[0].get("query", None))
Expand Down
2 changes: 1 addition & 1 deletion structured_query/llm_service_structured_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ async def get_structured_query(query: str):
Description: Get the query, replace %20 with space and invoke the chain to get the answers based on the prompt.
"""
response, filter_condition = None, None
try:
query = query.replace("%20", " ")
response = chain.invoke({"query": query})
Expand All @@ -47,7 +48,6 @@ async def get_structured_query(query: str):

except Exception as e:
print(f"An error occurred: ", HTTPException(status_code=500, detail=f"An error occurred: {e}"))
response, filter_condition = None, None

return response, filter_condition

Expand Down

0 comments on commit f740fbe

Please sign in to comment.