|
|
import os |
|
|
from google import genai |
|
|
from dotenv import load_dotenv |
|
|
from PIL import Image |
|
|
|
|
|
load_dotenv() |
|
|
|
|
|
class ClaimsIntakeAgent: |
|
|
def __init__(self): |
|
|
api_key = os.getenv("GEMINI_API_KEY") |
|
|
if not api_key: |
|
|
print("Warning: GEMINI_API_KEY not found in environment variables.") |
|
|
else: |
|
|
self.client = genai.Client(api_key=api_key) |
|
|
|
|
|
def process_claim(self, user_input, image=None, document_path=None): |
|
|
""" |
|
|
Processes a user claim report. |
|
|
Args: |
|
|
user_input (str): The user's description of the accident. |
|
|
image (PIL.Image): Optional image of the damage. |
|
|
document_path (str): Optional path to a uploaded document (PDF/Doc). |
|
|
Returns: |
|
|
str: The agent's response. |
|
|
""" |
|
|
if not hasattr(self, 'client'): |
|
|
return "Error: Gemini API key not configured. Please check your .env file." |
|
|
|
|
|
from utils import convert_doc_to_markdown |
|
|
doc_content = "" |
|
|
if document_path: |
|
|
doc_content = convert_doc_to_markdown(document_path) |
|
|
doc_content = f"\n\n**Uploaded Document Content:**\n{doc_content}\n" |
|
|
print("Extracted content:",doc_content) |
|
|
prompt = f""" |
|
|
You are an AI assistant for an auto insurance company. Your goal is to help users report vehicle claims and provide a preliminary assessment for the back-office. |
|
|
Analyze the user's input, any provided images, and any uploaded document content. |
|
|
|
|
|
If an image is provided, estimate the damage severity and cost (in GBP) based on visual inspection. |
|
|
Extract vehicle information if possible. |
|
|
Analyze the text and documents for consistency and potential fraud indicators. |
|
|
|
|
|
**Uploaded Document Content:** |
|
|
{doc_content} |
|
|
|
|
|
Return a structured response in the following format: |
|
|
|
|
|
**Claim Assessment** |
|
|
* **Submitter Name:** [Name if found in text/docs, else 'Anonymous'] |
|
|
* **Vehicle:** [Vehicle Make/Model/Year if identifiable, else 'Unknown'] |
|
|
* **Damage Severity:** [Minor/Moderate/Severe] |
|
|
* **Estimated Repair Cost:** [Amount in £] |
|
|
* **Fraud Risk:** [Low/Medium/High] - [Brief reason] |
|
|
* **Adjuster Classification:** [Junior Adjuster/Senior Adjuster] (Route complex/high-risk/high-value >£5000 claims to Senior) |
|
|
* **Policy Check:** Coverage appears valid (Simulated). |
|
|
* **Summary:** [Concise summary of the incident and findings] |
|
|
* **Next Steps:** [Brief instruction to user] |
|
|
|
|
|
If no image is provided, ask the user to upload one for a better assessment, but still acknowledge the report. |
|
|
""" |
|
|
|
|
|
try: |
|
|
inputs = [prompt, user_input] |
|
|
if image: |
|
|
inputs.append(image) |
|
|
|
|
|
response = self.client.models.generate_content( |
|
|
model='gemini-2.5-flash', |
|
|
contents=inputs |
|
|
) |
|
|
return response.text |
|
|
except Exception as e: |
|
|
return f"Error processing claim: {str(e)}" |
|
|
|
|
|
def analyze_document(self, file_path): |
|
|
""" |
|
|
Analyzes an uploaded document (PDF/Image) for claim info. |
|
|
For MVP, this handles images primarily, but could be expanded for PDFs. |
|
|
""" |
|
|
|
|
|
return "Document received. Analysis feature is in beta (MVP)." |
|
|
|