Update app.py
Browse files
app.py
CHANGED
|
@@ -20,7 +20,6 @@ from langchain.document_loaders import TextLoader
|
|
| 20 |
from langchain.memory import ConversationBufferMemory
|
| 21 |
from langchain.agents import initialize_agent, Tool
|
| 22 |
from langchain.agents.agent_types import AgentType
|
| 23 |
-
from langchain.schema import messages_from_dict, messages_to_dict
|
| 24 |
|
| 25 |
class AbbyyVantage:
|
| 26 |
"""
|
|
@@ -248,11 +247,12 @@ def setup_agent(file):
|
|
| 248 |
|
| 249 |
agent_executor = initialize_agent(
|
| 250 |
tools=tools,
|
| 251 |
-
llm=ChatOpenAI(model="gpt-3.5-turbo"),
|
| 252 |
-
|
|
|
|
|
|
|
| 253 |
memory=memory,
|
| 254 |
-
verbose=True
|
| 255 |
-
return_intermediate_steps=True
|
| 256 |
)
|
| 257 |
|
| 258 |
print("|--Agent setup complete")
|
|
@@ -286,6 +286,9 @@ def ask_question(message, history):
|
|
| 286 |
"**💡 Advisor’s Practical Tip:**\n"
|
| 287 |
"- Give actionable tips to help the user get the most from their policy.\n\n"
|
| 288 |
|
|
|
|
|
|
|
|
|
|
| 289 |
"Your tone should be empathetic and clear—like a smart, helpful insurance advisor.\n"
|
| 290 |
"Format everything using **Markdown**. Always include all four sections in the output.\n\n"
|
| 291 |
|
|
@@ -296,6 +299,8 @@ def ask_question(message, history):
|
|
| 296 |
"**🧠 Simplified Explanation:**\n"
|
| 297 |
"- ...\n\n"
|
| 298 |
"**💡 Advisor’s Practical Tip:**\n"
|
|
|
|
|
|
|
| 299 |
"- ...\n"
|
| 300 |
"---"
|
| 301 |
"---\n"
|
|
@@ -303,6 +308,7 @@ def ask_question(message, history):
|
|
| 303 |
"**📄 Policy Details:**\n- The policy offers 24-month waiting period for pre-existing conditions.\n\n"
|
| 304 |
"**🧠 Simplified Explanation:**\n- You have to wait 2 years before claims related to past illnesses are covered.\n\n"
|
| 305 |
"**💡 Advisor’s Practical Tip:**\n- Consider a top-up or rider that waives this waiting period.\n\n"
|
|
|
|
| 306 |
)
|
| 307 |
|
| 308 |
|
|
@@ -310,21 +316,8 @@ def ask_question(message, history):
|
|
| 310 |
prompt = f"{advisory_prompt}\nQuestion: {message}"
|
| 311 |
|
| 312 |
try:
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
final_output = result.get("output", "No output.")
|
| 316 |
-
steps = result.get("intermediate_steps", [])
|
| 317 |
-
|
| 318 |
-
steps_md = "\n\n<details><summary>🧠 Agent Thought Process</summary>\n\n"
|
| 319 |
-
for i, (action, observation) in enumerate(steps, 1):
|
| 320 |
-
steps_md += f"**Step {i}**\n\n"
|
| 321 |
-
steps_md += f"- **Thought**: {action.log.strip()}\n"
|
| 322 |
-
steps_md += f"- **Tool Used**: `{action.tool}` with input `{action.tool_input}`\n"
|
| 323 |
-
steps_md += f"- **Observation**: {observation.strip()}\n\n"
|
| 324 |
-
steps_md += "</details>"
|
| 325 |
-
|
| 326 |
-
return steps_md + "\n\n" + final_output
|
| 327 |
-
|
| 328 |
except Exception as e:
|
| 329 |
return f"❌ Error: {str(e)}"
|
| 330 |
|
|
|
|
| 20 |
from langchain.memory import ConversationBufferMemory
|
| 21 |
from langchain.agents import initialize_agent, Tool
|
| 22 |
from langchain.agents.agent_types import AgentType
|
|
|
|
| 23 |
|
| 24 |
class AbbyyVantage:
|
| 25 |
"""
|
|
|
|
| 247 |
|
| 248 |
agent_executor = initialize_agent(
|
| 249 |
tools=tools,
|
| 250 |
+
#llm=ChatOpenAI(model="gpt-3.5-turbo"),
|
| 251 |
+
llm=ChatOpenAI(model="gpt-4o),
|
| 252 |
+
agent=AgentType.CONVERSATIONAL_REACT_DESCRIPTION,
|
| 253 |
+
#agent=AgentType.CHAT_CONVERSATIONAL_REACT_DESCRIPTION,
|
| 254 |
memory=memory,
|
| 255 |
+
verbose=True
|
|
|
|
| 256 |
)
|
| 257 |
|
| 258 |
print("|--Agent setup complete")
|
|
|
|
| 286 |
"**💡 Advisor’s Practical Tip:**\n"
|
| 287 |
"- Give actionable tips to help the user get the most from their policy.\n\n"
|
| 288 |
|
| 289 |
+
"**⚠️ Caveats and Exclusions:**\n"
|
| 290 |
+
"- Mention any exclusions, limitations, or waiting periods.\n\n"
|
| 291 |
+
|
| 292 |
"Your tone should be empathetic and clear—like a smart, helpful insurance advisor.\n"
|
| 293 |
"Format everything using **Markdown**. Always include all four sections in the output.\n\n"
|
| 294 |
|
|
|
|
| 299 |
"**🧠 Simplified Explanation:**\n"
|
| 300 |
"- ...\n\n"
|
| 301 |
"**💡 Advisor’s Practical Tip:**\n"
|
| 302 |
+
"- ...\n\n"
|
| 303 |
+
"**⚠️ Caveats and Exclusions:**\n"
|
| 304 |
"- ...\n"
|
| 305 |
"---"
|
| 306 |
"---\n"
|
|
|
|
| 308 |
"**📄 Policy Details:**\n- The policy offers 24-month waiting period for pre-existing conditions.\n\n"
|
| 309 |
"**🧠 Simplified Explanation:**\n- You have to wait 2 years before claims related to past illnesses are covered.\n\n"
|
| 310 |
"**💡 Advisor’s Practical Tip:**\n- Consider a top-up or rider that waives this waiting period.\n\n"
|
| 311 |
+
"**⚠️ Caveats and Exclusions:**\n- Diabetes and hypertension are included in pre-existing illnesses list.\n\n"
|
| 312 |
)
|
| 313 |
|
| 314 |
|
|
|
|
| 316 |
prompt = f"{advisory_prompt}\nQuestion: {message}"
|
| 317 |
|
| 318 |
try:
|
| 319 |
+
response = agent_executor.run(prompt)
|
| 320 |
+
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
except Exception as e:
|
| 322 |
return f"❌ Error: {str(e)}"
|
| 323 |
|