File size: 1,165 Bytes
fb38df2
83fe4f9
 
 
 
fb38df2
 
83fe4f9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from backend.ai.client import llm_client, render_prompt
from backend.ai.prompts import EXTRACT_PROMPT


def extract_email_data(from_email: str, subject: str, body: str) -> dict:
    if llm_client.is_ready():
        return llm_client.generate_json(
            render_prompt(
                EXTRACT_PROMPT,
                from_email=from_email,
                subject=subject,
                body=body,
            )
        )

    is_order = "order" in subject.lower() or "order" in body.lower()
    return {
        "is_order": is_order,
        "message_type": "order" if is_order else "question",
        "confidence": 0.91 if is_order else 0.72,
        "customer_name": from_email.split("@")[0].replace(".", " ").title(),
        "customer_email": from_email,
        "items": [{"name": "Honeycrisp apples", "quantity": 2}] if is_order else [],
        "pickup_date": "next available pickup",
        "special_requests": "",
        "needs_clarification": not is_order,
        "clarification_question": "Can you confirm the items and quantities?" if not is_order else "",
        "suggested_response": "Thanks for the note. I can help with that.",
    }