Last active
May 26, 2025 08:16
-
-
Save petrosDemetrakopoulos/049c3f023761264a829c251d17be0804 to your computer and use it in GitHub Desktop.
Mail classification using AI waterfall
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def classify_email_basic(email_content, subject): | |
# Support tickets | |
if re.search(r'\b(help|support|issue|problem|bug|error)\b', subject.lower()): | |
return 'support' | |
# Sales inquiries | |
if re.search(r'\b(quote|pricing|purchase|buy|demo)\b', subject.lower()): | |
return 'sales' | |
# HR/Recruitment | |
if re.search(r'\b(job|career|interview|resume|hiring)\b', subject.lower()): | |
return 'hr' | |
# If no pattern matches, escalate to LLM | |
client = OpenAI(api_key=API_KEY) | |
prompt = | |
f""" | |
Classify the following email into one of the following categories | |
1. Support - For support tickets and issues | |
2. Sales - For sales inquiries, pricing etc. | |
3. HR - For recruitment inquiries, interviews scheduling etc. | |
{subject} {email_content} | |
""" | |
llm_classification = client.responses.create(model='gpt-4.1', input=prompt).output_tex | |
return llm_classification |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment