Jakarta Black Consulting
Home
Get Started
Chapter13
Jakarta Black Consulting
Home
Get Started
Chapter13
More
  • Home
  • Get Started
  • Chapter13
  • Home
  • Get Started
  • Chapter13

Chapter 13 Python Code

from openai import OpenAI


client = OpenAI()


def classify_email(email_text):

    prompt = f"""

    You are an Email Triage and Escalation Agent.


    Classify the email into one of the following categories:

    - Routine Inquiry

    - Operational Issue

    - Customer Escalation

    - Legal or Compliance Risk

    - Executive Priority


    Also determine:

    - Escalation Required (Yes/No)

    - Priority Level (Low/Medium/High)

    - Confidence Level (High/Medium/Low)

    - One sentence reasoning.


    Email:

    {email_text}

    """


    response = client.chat.completions.create(

        model="gpt-4o-mini",

        messages=[{"role": "user", "content": prompt}]

    )


    return response.choices[0].message.content



with open("emails.txt", "r") as file:

    content = file.read()

    emails = content.split("Subject:")


for email in emails:

    if email.strip():

        print("--------------------------------------------------")

        print("Email:")

        print(email.strip())

        print("\nClassification Result:")

        result = classify_email(email.strip())

        print(result)

        print("--------------------------------------------------\n") 

Jakarta Black Consulting

Copyright © 2026 Jakarta Black Consulting - All Rights Reserved.

This website uses cookies.

We use cookies to analyze website traffic and optimize your website experience. By accepting our use of cookies, your data will be aggregated with all other user data.

Accept