FastAPI-based email parsing service using LLM for structured data extraction with Oracle Cloud Infrastructure (OCI).
- Docker
- Docker Compose
- OCI credentials (config + private key)
.
├── Dockerfile
├── docker-compose.yml
├── requirements.txt
├── .dockerignore
├── main.py # FastAPI application
├── llm_client.py # LLM client with OCI integration
├── structured_output.py # Pydantic models
├── prompt.md # LLM prompts
└── app/config/
├── config # OCI config file (includes model and compartment_id)
└── oci_api_key.pem # OCI private key
- Login to OCI Console -> Identity & security -> Users
- Select user -> API Keys -> Add API Key
- Generate private Key
- Dowload both the
.pemand the config file - Compile the config file's field "key_file" with the path of the .pem you just dowloaded
The project expects the OCI configuration to be located inside the repository at:
./app/config
This directory is mounted into the container at:
/app/config
Make sure you have:
app/config/config— OCI CLI config fileapp/config/oci_api_key.pem— OCI private key
[DEFAULT]
user=ocid1.user.oc1..xxxxx
fingerprint=xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx
tenancy=ocid1.tenancy.oc1..xxxxx
region=eu-frankfurt-1
key_file=/app/config/oci_api_key.pem
# LLM specific settings
model=cohere.command-a-03-2025
oci_compartment_id=ocid1.compartment.oc1..xxxxx-
key_filemust use the container path:/app/config/oci_api_key.pem
docker-compose up -d --builddocker-compose logs -fdocker-compose down# Build image
docker build -t email-parser-api .
# Run container
docker run -d \
-p 8080:8080 \
-v ./app/config:/app/config:ro \
--name email-parser-api \
email-parser-api
# Logs
docker logs -f email-parser-api
# Stop & remove
docker stop email-parser-api
docker rm email-parser-apiOnce running:
- Swagger UI: http://localhost:8080/docs
- ReDoc: http://localhost:8080/redoc
GET /— Root endpointGET /health— Health checkPOST /parse-email— Parse email content
curl -X POST "http://localhost:8080/parse-email" \
-H "Content-Type: application/json" \
-d '{
"email_body": "From: john.doe@example.com\nTo: support@company.com\nSubject: Order Issue\nDate: 2024-01-15\n\nHello,\n\nI have an issue with my recent order #12345.\n\nBest regards,\nJohn Doe"
}'{
"emails": [
{
"CUSTOMER_NAME": "John Doe",
"MAIL_TYPE": "TO",
"CUSTOMER_OPERATOR": "john.doe@example.com",
"TOPIC": "Order Issue",
"MAIL_DATE": "2024-01-15"
}
],
"FULL_BODY": "Hello,\n\nI have an issue with my recent order #12345.\n\nBest regards,\nJohn Doe"
}python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
uvicorn main:app --reload --host 0.0.0.0 --port 8080Add to .gitignore:
app/config/config
app/config/oci_api_key.pem- Check
app/config/config - Check
app/config/oci_api_key.pem - Verify
key_file=/app/config/oci_api_key.pem
- Verify
modelvalue - Check region compatibility
- Verify
oci_compartment_id - Check permissions on compartment