Update app.py
Browse files
app.py
CHANGED
|
@@ -78,7 +78,11 @@ llm_model = None
|
|
| 78 |
# ==========================================
|
| 79 |
@tool
|
| 80 |
def parse_claim(json_data: str) -> str:
|
| 81 |
-
"""Parses claim JSON data to validate structure.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
try:
|
| 83 |
data = json.loads(json_data)
|
| 84 |
claim_info = ClaimInfo.model_validate(data)
|
|
@@ -88,7 +92,11 @@ def parse_claim(json_data: str) -> str:
|
|
| 88 |
|
| 89 |
@tool
|
| 90 |
def is_valid_query(query: str) -> str:
|
| 91 |
-
"""Validates policy standing and dates against coverage database.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
try:
|
| 93 |
claim_info = ClaimInfo.model_validate_json(query)
|
| 94 |
import csv
|
|
@@ -118,7 +126,11 @@ def is_valid_query(query: str) -> str:
|
|
| 118 |
|
| 119 |
@tool
|
| 120 |
def generate_policy_queries(claim_info_json: str) -> str:
|
| 121 |
-
"""Generate queries to retrieve relevant policy sections based on claim info.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
global llm_model
|
| 123 |
prompt = f"""
|
| 124 |
Analyze the following auto insurance claim to identify 3-5 key policy sections to consult:
|
|
@@ -137,7 +149,11 @@ def generate_policy_queries(claim_info_json: str) -> str:
|
|
| 137 |
|
| 138 |
@tool
|
| 139 |
def retrieve_policy_text(queries_json: str) -> str:
|
| 140 |
-
"""Retrieves policy text from ChromaDB using generated queries.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
try:
|
| 142 |
queries_data = json.loads(queries_json)
|
| 143 |
query_strings = queries_data.get("queries", [])
|
|
@@ -153,7 +169,12 @@ def retrieve_policy_text(queries_json: str) -> str:
|
|
| 153 |
|
| 154 |
@tool
|
| 155 |
def generate_recommendation(claim_info_json: str, policy_text: str) -> str:
|
| 156 |
-
"""Generate a policy recommendation based on claim info and retrieved policy text.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
global llm_model
|
| 158 |
prompt = f"""
|
| 159 |
Evaluate the following auto insurance claim against the policy text:
|
|
@@ -180,7 +201,12 @@ def generate_recommendation(claim_info_json: str, policy_text: str) -> str:
|
|
| 180 |
|
| 181 |
@tool
|
| 182 |
def finalize_decision(claim_info_json: str, recommendation_json: str) -> str:
|
| 183 |
-
"""Finalize the claim decision based on the recommendation and format output.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
try:
|
| 185 |
claim_info = ClaimInfo.model_validate_json(claim_info_json)
|
| 186 |
rec_data = json.loads(recommendation_json)
|
|
|
|
| 78 |
# ==========================================
|
| 79 |
@tool
|
| 80 |
def parse_claim(json_data: str) -> str:
|
| 81 |
+
"""Parses claim JSON data to validate structure.
|
| 82 |
+
|
| 83 |
+
Args:
|
| 84 |
+
json_data: The raw JSON string containing the claim data.
|
| 85 |
+
"""
|
| 86 |
try:
|
| 87 |
data = json.loads(json_data)
|
| 88 |
claim_info = ClaimInfo.model_validate(data)
|
|
|
|
| 92 |
|
| 93 |
@tool
|
| 94 |
def is_valid_query(query: str) -> str:
|
| 95 |
+
"""Validates policy standing and dates against coverage database.
|
| 96 |
+
|
| 97 |
+
Args:
|
| 98 |
+
query: The parsed claim JSON string.
|
| 99 |
+
"""
|
| 100 |
try:
|
| 101 |
claim_info = ClaimInfo.model_validate_json(query)
|
| 102 |
import csv
|
|
|
|
| 126 |
|
| 127 |
@tool
|
| 128 |
def generate_policy_queries(claim_info_json: str) -> str:
|
| 129 |
+
"""Generate queries to retrieve relevant policy sections based on claim info.
|
| 130 |
+
|
| 131 |
+
Args:
|
| 132 |
+
claim_info_json: A JSON string containing the parsed claim details.
|
| 133 |
+
"""
|
| 134 |
global llm_model
|
| 135 |
prompt = f"""
|
| 136 |
Analyze the following auto insurance claim to identify 3-5 key policy sections to consult:
|
|
|
|
| 149 |
|
| 150 |
@tool
|
| 151 |
def retrieve_policy_text(queries_json: str) -> str:
|
| 152 |
+
"""Retrieves policy text from ChromaDB using generated queries.
|
| 153 |
+
|
| 154 |
+
Args:
|
| 155 |
+
queries_json: A JSON string containing a list of search queries.
|
| 156 |
+
"""
|
| 157 |
try:
|
| 158 |
queries_data = json.loads(queries_json)
|
| 159 |
query_strings = queries_data.get("queries", [])
|
|
|
|
| 169 |
|
| 170 |
@tool
|
| 171 |
def generate_recommendation(claim_info_json: str, policy_text: str) -> str:
|
| 172 |
+
"""Generate a policy recommendation based on claim info and retrieved policy text.
|
| 173 |
+
|
| 174 |
+
Args:
|
| 175 |
+
claim_info_json: The validated claim info in JSON format.
|
| 176 |
+
policy_text: The relevant text retrieved from the policy documents.
|
| 177 |
+
"""
|
| 178 |
global llm_model
|
| 179 |
prompt = f"""
|
| 180 |
Evaluate the following auto insurance claim against the policy text:
|
|
|
|
| 201 |
|
| 202 |
@tool
|
| 203 |
def finalize_decision(claim_info_json: str, recommendation_json: str) -> str:
|
| 204 |
+
"""Finalize the claim decision based on the recommendation and format output.
|
| 205 |
+
|
| 206 |
+
Args:
|
| 207 |
+
claim_info_json: The validated claim information.
|
| 208 |
+
recommendation_json: The AI-generated recommendation output.
|
| 209 |
+
"""
|
| 210 |
try:
|
| 211 |
claim_info = ClaimInfo.model_validate_json(claim_info_json)
|
| 212 |
rec_data = json.loads(recommendation_json)
|