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.", }