Sulaiman8 commited on
Commit
cfc76e9
·
verified ·
1 Parent(s): 52868e3

Fix intent classification bug

Browse files
Files changed (1) hide show
  1. app.py +27 -20
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, the card names need not end with "card" keyword, so also consider that (e.g., "Tell me about HDFC Regalia", "Is SBI Elite good?").
545
- 3. "no_retrieval" → If the query is generic, chit-chat, or doesn't need credit card data lookup (e.g., "What is interest in credit cards?").
546
-
547
- Respond in the following JSON format:
548
- {{
549
- "intent": "retrieve" | "specific" | "no_retrieval",
550
- "response": "Only include this if intent is 'no_retrieval'"
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
- # print(handle_query_classification("what is a credit card"))
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()