A Streamlit web app that generates professional emails from three inputs — Intent, Key Facts, and Tone — using the OpenAI GPT-4o-mini API.
email-assistant/
├── app.py # Streamlit UI (Part 1)
├── generator.py # Shared OpenAI call logic
├── prompts.py # Prompt template (Model A — advanced)
├── metrics.py # 3 custom evaluation metrics (Part 2)
├── scenarios.json # 10 test scenarios + human reference emails
├── evaluate.py # Runs Model A evaluation, writes results
├── evaluate_second_model.py # Runs Model B evaluation (Part 3 comparison)
├── evaluation_results.json # Model A full report
├── evaluation_results.csv # Model A scores
├── evaluation_results_modelB.json # Model B full report
├── evaluation_results_modelB.csv # Model B scores
├── requirements.txt # Python dependencies
├── .env # Template for API key
└── README.md
This assistant uses a combined Role-Playing + Chain-of-Thought + Per-Tone Guide strategy (see prompts.py):
- Role-Playing — anchors the model to an "expert executive assistant" persona, calibrating professionalism and vocabulary automatically.
- Chain-of-Thought — forces the model to reason through intent → facts → tone → structure before drafting, improving fact recall and tone accuracy.
- Per-Tone Guide — provides concrete, tone-specific instructions (e.g. Urgent → "Short sentences. Lead with the critical information immediately.") so the model commits to the requested tone rather than defaulting to generic professional writing.
These three techniques directly target the dimensions measured by the 3 custom evaluation metrics in Part 2.
git clone https://github.com/your-username/email-assistant.git
cd email-assistantpython -m venv myenvWindows:
myenv\Scripts\activateMac/Linux:
source myenv/bin/activatepip install -r requirements.txtCopy .env.example to .env and add your OpenAI API key:
OPENAI_API_KEY=sk-proj-xxxxxxxxxxxxxxxx
Get a key at: https://platform.openai.com/api-keys
streamlit run app.pyOpens at http://localhost:8501. Enter your intent, key facts, and choose a tone, then click Generate Email.
python evaluate.pyRuns all 10 scenarios through the assistant (Model A) and scores them using the 3 custom metrics. Outputs:
evaluation_results.json— full report including metric definitions and generated emailsevaluation_results.csv— flat scores for spreadsheet review
python evaluate_second_model.pyRuns the same 10 scenarios using Model B (simple prompt, no per-tone guide). Outputs:
evaluation_results_modelB.jsonevaluation_results_modelB.csv
| Metric | Type | What it measures |
|---|---|---|
fact_recall |
Rule-based | % of supplied key facts whose keywords appear in the output |
tone_accuracy |
LLM-as-Judge | GPT-4o-mini rates 1–5 how well writing style matches requested tone |
conciseness_clarity |
Hybrid | Average of length-ratio score vs reference email + LLM clarity rating |
streamlit
openai
python-dotenv
Install with:
pip install -r requirements.txt