Sulaiman8 commited on
Commit
e4a0d78
·
verified ·
1 Parent(s): 72963f5

Delete agents

Browse files
Files changed (2) hide show
  1. agents/chat.py +0 -68
  2. agents/compare.py +0 -37
agents/chat.py DELETED
@@ -1,68 +0,0 @@
1
- import pandas as pd
2
- import google.generativeai as genai
3
- import os
4
- from app import eligibility_df
5
-
6
- #function for the chatbot functionality
7
- eligibility_lookup = {}
8
- for _, row in eligibility_df.iterrows():
9
- card_name = row["Name"].strip()
10
- eligibility_info = f"""
11
- - Bank: {row['Bank']}
12
- - Age: {row['Minimum Age']} to {row['Maximum Age']}
13
- - Minimum Income: {row['Minimum Income (LPA)']} LPA
14
- - Minimum Credit Score: {row['Minimum Credit Score']}
15
- - Joining Fee: ₹{row['Joining fee']}
16
- - Annual Fee: ₹{row['Annual fee']}
17
- """
18
- eligibility_lookup[card_name] = eligibility_info.strip()
19
-
20
- # Function to handle chat interaction with Gemini
21
- def chat_with_gemini(user_query, user_message, chat_history, card_lookup):
22
- genai.configure(api_key=os.environ.get("api_key_4"))
23
- model4 = genai.GenerativeModel('gemini-1.5-flash-latest')
24
- context = ""
25
- for name, desc in list(card_lookup.items())[:5]:
26
- eligibility_info = eligibility_lookup.get(name, "No eligibility or fee information available.")
27
- full_desc = f"{desc}\n\nEligibility & Fees:\n{eligibility_info}"
28
- context += f"{name}:\n{full_desc}\n\n"
29
- recent_user_messages = [
30
- msg["content"] for msg in chat_history if msg["role"] == "user"
31
- ][-5:]
32
-
33
- conversation = f"""
34
- You are a helpful financial assistant. A user has already shared their overall credit card preferences.
35
-
36
- ### User’s Requirements:
37
- {user_query}
38
-
39
- ### Credit Card Options:
40
- {context}
41
-
42
- ### User's Follow-up Question:
43
- {user_message}
44
-
45
- ### Recent User Messages:
46
- {recent_user_messages}
47
-
48
- ### Instructions:
49
- 1. Answer the user's current question clearly and concisely.
50
- 2. Always consider the user's overall requirements above.
51
- 3. Use only the card descriptions provided. Do not assume or invent any card benefits.
52
- 4. If the user asks which card is best or suitable for their needs, use the user’s requirements above to select and explain.
53
- 5. Don't ask the user to restate their requirements — they're already provided above.
54
- """
55
- # print(conversation)
56
- try:
57
- response = model4.generate_content(conversation)
58
- gemini_response = response.text
59
-
60
- chat_history.append({"role": "user", "content": user_message})
61
- chat_history.append({"role": "assistant", "content": gemini_response})
62
-
63
- except Exception as e:
64
- error_msg = "Error: Unable to retrieve response from Gemini. Please try again later."
65
- chat_history.append({"role": "user", "content": user_message})
66
- chat_history.append({"role": "assistant", "content": error_msg})
67
-
68
- return chat_history, chat_history
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
agents/compare.py DELETED
@@ -1,37 +0,0 @@
1
- import pandas as pd
2
- import google.generativeai as genai
3
- import os
4
-
5
- #function to compare cards
6
- def compare_selected_cards(selected_names, card_lookup):
7
- genai.configure(api_key=os.environ.get("api_key_4"))
8
- model4 = genai.GenerativeModel('gemini-1.5-flash-latest')
9
- print(selected_names)
10
- if not selected_names or len(selected_names) < 2:
11
- return "<b style='color:red;'>Please select at least two cards to compare.</b>"
12
-
13
- comparison_data = "\n\n".join([
14
- f"{name}: {card_lookup.get(name)}" for name in selected_names
15
- ])
16
- prompt = (
17
- f"Do not include extra symbols like (* or #), just generate a textual response maybe with numbers for points."
18
- f"Compare the following credit cards based on their benefits. "
19
- f"Keep the output short, structured, and very readable:\n\n"
20
- f"{comparison_data}\n\n"
21
- f"Use markdown format with clear section headers like 'Comparison' and 'Recommendation'. "
22
- f"Present key differences as bullet points without using '*' symbols — use '-' instead. "
23
- f"Make it crisp and avoid lengthy explanations. "
24
- f"Conclude with a recommendation on which card suits which type of user."
25
- f"DO NOT INCLUDE ANY SYMBOLS LIKE # OR *"
26
- )
27
- print("comparing")
28
- try:
29
- response = model4.generate_content(prompt)
30
- return f"""
31
- <div style='background-color: #f9fbe7; padding: 15px; border-radius: 10px; font-family: sans-serif;'>
32
- <pre style='white-space: pre-wrap; font-size: 13px; color: #333;'>{response.text}</pre>
33
- </div>
34
- """
35
- except Exception as e:
36
- print("Comparison Error:", e)
37
- return "<b style='color:red;'>Something went wrong while comparing. Please try again.</b>"