All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 5m3s
89 lines
2.3 KiB
Markdown
89 lines
2.3 KiB
Markdown
# email-classifier
|
|
|
|
FastAPI service that classifies email using a configurable LLM backend.
|
|
|
|
## What changed
|
|
|
|
The classifier no longer hardcodes a single Ollama + OpenAI-compatible endpoint.
|
|
It now supports:
|
|
- OpenAI-compatible APIs
|
|
- Anthropic-compatible APIs
|
|
- per-request overrides for provider, model, endpoint, and temperature
|
|
- global defaults through environment variables
|
|
|
|
This makes it suitable for local Ollama, hosted OpenAI-compatible services, and MiniMax's recommended Anthropic-compatible API.
|
|
|
|
## Environment configuration
|
|
|
|
Defaults are loaded from environment variables:
|
|
|
|
```bash
|
|
export LLM_PROVIDER=openai
|
|
export LLM_BASE_URL=http://ollama.internal.henryhosted.com:9292/v1
|
|
export LLM_API_KEY=none
|
|
export LLM_MODEL=qwen2.5-7b-instruct.q4_k_m
|
|
export LLM_TEMPERATURE=0.1
|
|
export LLM_TIMEOUT_SECONDS=60
|
|
export LLM_MAX_RETRIES=3
|
|
```
|
|
|
|
### MiniMax example
|
|
|
|
MiniMax recommends Anthropic-compatible integration.
|
|
|
|
```bash
|
|
export LLM_PROVIDER=anthropic
|
|
export LLM_BASE_URL=https://api.minimax.io/v1
|
|
export LLM_API_KEY=your_minimax_key
|
|
export LLM_MODEL=MiniMax-M2.7
|
|
```
|
|
|
|
## API
|
|
|
|
### POST /classify
|
|
|
|
Request body:
|
|
|
|
```json
|
|
{
|
|
"email_data": {
|
|
"subject": "Can you review this by Friday?",
|
|
"body": "Hi Daniel, please review the attached budget proposal."
|
|
},
|
|
"provider": "anthropic",
|
|
"base_url": "https://api.minimax.io/v1",
|
|
"model": "MiniMax-M2.7",
|
|
"temperature": 0.1
|
|
}
|
|
```
|
|
|
|
All override fields are optional. If omitted, the service uses the global env config.
|
|
|
|
Response shape:
|
|
|
|
```json
|
|
{
|
|
"needs_action": true,
|
|
"category": "question",
|
|
"priority": "high",
|
|
"task_description": "Review the budget proposal and respond by Friday",
|
|
"reasoning": "Direct request with a deadline requires follow-up",
|
|
"confidence": 0.91
|
|
}
|
|
```
|
|
|
|
## Architecture
|
|
|
|
- `app/config.py`: global and per-request LLM settings
|
|
- `app/llm_adapters.py`: provider adapters
|
|
- `app/classifier.py`: classification orchestration, retries, normalization
|
|
- `app/prompts.py`: system prompt
|
|
- `app/routers/classify_email.py`: thin API route
|
|
|
|
## Notes
|
|
|
|
- OpenAI-compatible providers use the OpenAI SDK.
|
|
- Anthropic-compatible providers use the Anthropic SDK.
|
|
- Per-request `api_key` is supported, but excluded from response serialization.
|
|
- The service normalizes malformed model output and falls back safely after retry exhaustion.
|