flow-pilot / backend /ai /classifier.py
DevelopedBy-Siva
deploy to HF
fb38df2
from backend.ai.client import llm_client, render_prompt
from backend.ai.prompts import CLASSIFY_PROMPT
def classify_email(from_email: str, subject: str, body: str, business_context: str) -> dict:
if llm_client.is_ready():
return llm_client.generate_json(
render_prompt(
CLASSIFY_PROMPT,
categories="order, availability_inquiry, complaint, greeting, other",
from_email=from_email,
subject=subject,
body=body,
business_context=business_context,
)
)
text = f"{subject} {body}".lower()
category = "order" if "order" in text else "availability_inquiry" if "available" in text else "other"
priority = "high" if "restaurant" in from_email.lower() else "medium"
return {
"category": category,
"priority": priority,
"requires_response": True,
"sentiment": "neutral",
"reasoning": "Derived from keywords and sender profile.",
}