Fix intent classification bug
Browse files
app.py
CHANGED
|
@@ -533,23 +533,29 @@ def handle_query_classification(user_query):
|
|
| 533 |
genai.configure(api_key='AIzaSyDGc7l82E1sa4GarTfGiTXC6dLD7Crk8oo')
|
| 534 |
model1 = genai.GenerativeModel('gemini-1.5-flash-latest')
|
| 535 |
prompt = f"""
|
| 536 |
-
You are a smart financial assistant.
|
| 537 |
-
|
| 538 |
-
### User's Query:
|
| 539 |
-
{user_query}
|
| 540 |
-
|
| 541 |
-
### Task:
|
| 542 |
-
Classify the user's intent into one of the following categories:
|
| 543 |
-
1. "retrieve" → If the user is asking for card suggestions, recommendations, or showing cards (e.g., "suggest a card", "need a travel card").
|
| 544 |
-
2. "specific" → If the user is asking about a particular card by name
|
| 545 |
-
3. "no_retrieval" →
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 553 |
|
| 554 |
raw_response = model1.generate_content(prompt).text.strip()
|
| 555 |
|
|
@@ -566,9 +572,10 @@ Respond in the following JSON format:
|
|
| 566 |
print("JSON parsing error:", e)
|
| 567 |
print("Raw response from LLM:", raw_response)
|
| 568 |
raise
|
| 569 |
-
|
| 570 |
-
#
|
| 571 |
-
|
|
|
|
| 572 |
#passing the card mentioned in the user query
|
| 573 |
def find_matching_card(user_query):
|
| 574 |
lowered_query = user_query.lower()
|
|
|
|
| 533 |
genai.configure(api_key='AIzaSyDGc7l82E1sa4GarTfGiTXC6dLD7Crk8oo')
|
| 534 |
model1 = genai.GenerativeModel('gemini-1.5-flash-latest')
|
| 535 |
prompt = f"""
|
| 536 |
+
You are a smart financial assistant.
|
| 537 |
+
|
| 538 |
+
### User's Query:
|
| 539 |
+
{user_query}
|
| 540 |
+
|
| 541 |
+
### Task:
|
| 542 |
+
Classify the user's intent into one of the following categories:
|
| 543 |
+
1. "retrieve" → If the user is asking for card suggestions, recommendations, or showing cards (e.g., "suggest a card", "need a travel card") OR if they mention their lifestyle, income, spending, or needs (e.g., travel, shopping, fuel, rewards, luxury).
|
| 544 |
+
2. "specific" → If the user is asking about a particular credit card by name (even if the word "card" is not used). Examples: "Tell me about HDFC Regalia", "Is SBI Elite good?".
|
| 545 |
+
3. "no_retrieval" → ONLY if the query is generic (e.g., “What is credit score?”), casual chit-chat (e.g., “Hi”), or doesn’t mention any lifestyle, financial needs, or specific card names.
|
| 546 |
+
|
| 547 |
+
|
| 548 |
+
Respond ONLY in the following JSON format:
|
| 549 |
+
If intent is "no_retrieval", you MUST include a helpful 'response' field.
|
| 550 |
+
If intent is "retrieve" or "specific", do NOT include any response or explanation.
|
| 551 |
+
|
| 552 |
+
Respond in this exact format:
|
| 553 |
+
{{
|
| 554 |
+
"intent": "retrieve" | "specific" | "no_retrieval",
|
| 555 |
+
"response": "Only include this if intent is 'no_retrieval'"
|
| 556 |
+
}}
|
| 557 |
+
|
| 558 |
+
"""
|
| 559 |
|
| 560 |
raw_response = model1.generate_content(prompt).text.strip()
|
| 561 |
|
|
|
|
| 572 |
print("JSON parsing error:", e)
|
| 573 |
print("Raw response from LLM:", raw_response)
|
| 574 |
raise
|
| 575 |
+
# result = handle_query_classification("Want to optimize my spending – travel often, premium hotels, and online shopping.")
|
| 576 |
+
# if result["intent"] == "no_retrieval":
|
| 577 |
+
# print(result['response'])
|
| 578 |
+
|
| 579 |
#passing the card mentioned in the user query
|
| 580 |
def find_matching_card(user_query):
|
| 581 |
lowered_query = user_query.lower()
|