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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Summarize & Sentiment API
|
| 2 |
+
|
| 3 |
+
Production-style FastAPI service that exposes LLM-powered text summarization and sentiment analysis endpoints using the OpenAI Responses API.
|
| 4 |
+
|
| 5 |
+
Built as an AI engineering portfolio project to demonstrate clean API design, schema validation, resilient model-output parsing, and deployment-ready structure.
|
| 6 |
+
|
| 7 |
+
## Why This Project
|
| 8 |
+
|
| 9 |
+
This repository showcases practical applied-AI backend skills recruiters and hiring managers look for:
|
| 10 |
+
|
| 11 |
+
- Designing typed, testable API contracts with Pydantic
|
| 12 |
+
- Integrating LLMs into backend services (not just notebooks)
|
| 13 |
+
- Hardening model outputs with parsing/validation logic
|
| 14 |
+
- Implementing structured JSON logging (`structlog`) for observability
|
| 15 |
+
- Organizing code into routes, services, and schemas for maintainability
|
| 16 |
+
|
| 17 |
+
## Features
|
| 18 |
+
|
| 19 |
+
- **Health endpoint** for service uptime checks
|
| 20 |
+
- **Summarization endpoint** with length control
|
| 21 |
+
- **Sentiment endpoint** returning structured JSON (`sentiment`, `confidence`, `explanation`)
|
| 22 |
+
- **Strict validation and normalization** of model sentiment labels
|
| 23 |
+
- **Environment-driven config** (`OPENAI_API_KEY`, optional `OPENAI_MODEL`)
|
| 24 |
+
- **Render-friendly entrypoint** via `main.py` (`uvicorn main:app`)
|
| 25 |
+
|
| 26 |
+
## Tech Stack
|
| 27 |
+
|
| 28 |
+
- Python
|
| 29 |
+
- FastAPI
|
| 30 |
+
- OpenAI Python SDK (`responses.create`)
|
| 31 |
+
- Pydantic v2
|
| 32 |
+
- Structlog
|
| 33 |
+
- Uvicorn
|
| 34 |
+
- python-dotenv
|
| 35 |
+
|
| 36 |
+
## Project Structure
|
| 37 |
+
|
| 38 |
+
```text
|
| 39 |
+
.
|
| 40 |
+
├── app/
|
| 41 |
+
│ ├── main.py # FastAPI app factory, logging setup
|
| 42 |
+
│ ├── routes/
|
| 43 |
+
│ │ ├── health.py # GET /health
|
| 44 |
+
│ │ ├── summarize.py # POST /summarize
|
| 45 |
+
│ │ └── sentiment.py # POST /analyze-sentiment
|
| 46 |
+
│ ├── schemas/
|
| 47 |
+
│ │ └── models.py # Request/response models
|
| 48 |
+
│ └── services/
|
| 49 |
+
│ ├── summarize.py # LLM summarization logic
|
| 50 |
+
│ └── sentiment.py # LLM sentiment + robust JSON parsing
|
| 51 |
+
├── main.py # host entrypoint (uvicorn main:app)
|
| 52 |
+
└── requirements.txt
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
## API Endpoints
|
| 56 |
+
|
| 57 |
+
### `GET /health`
|
| 58 |
+
Returns status and timestamp.
|
| 59 |
+
|
| 60 |
+
### `POST /summarize`
|
| 61 |
+
Generates a concise summary.
|
| 62 |
+
|
| 63 |
+
**Request body**
|
| 64 |
+
```json
|
| 65 |
+
{
|
| 66 |
+
"text": "Long source text...",
|
| 67 |
+
"max_length": 80
|
| 68 |
+
}
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
**Response body**
|
| 72 |
+
```json
|
| 73 |
+
{
|
| 74 |
+
"summary": "Short summary text..."
|
| 75 |
+
}
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
### `POST /analyze-sentiment`
|
| 79 |
+
Analyzes sentiment and returns typed output.
|
| 80 |
+
|
| 81 |
+
**Request body**
|
| 82 |
+
```json
|
| 83 |
+
{
|
| 84 |
+
"text": "I loved how smooth this release felt!"
|
| 85 |
+
}
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
**Response body**
|
| 89 |
+
```json
|
| 90 |
+
{
|
| 91 |
+
"sentiment": "positive",
|
| 92 |
+
"confidence": 0.93,
|
| 93 |
+
"explanation": "The text expresses clear satisfaction and positive emotion."
|
| 94 |
+
}
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
## Local Setup
|
| 98 |
+
|
| 99 |
+
1. Clone and enter project
|
| 100 |
+
```bash
|
| 101 |
+
git clone https://github.com/zainabahmed4626-lab/AIEngineeringW1V2.git
|
| 102 |
+
cd AIEngineeringW1V2
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
2. Create virtual environment
|
| 106 |
+
```bash
|
| 107 |
+
python -m venv .venv
|
| 108 |
+
# Windows PowerShell
|
| 109 |
+
.venv\Scripts\Activate.ps1
|
| 110 |
+
```
|
| 111 |
+
|
| 112 |
+
3. Install dependencies
|
| 113 |
+
```bash
|
| 114 |
+
pip install -r requirements.txt
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
4. Configure environment variables
|
| 118 |
+
```env
|
| 119 |
+
OPENAI_API_KEY=your_openai_key
|
| 120 |
+
# Optional
|
| 121 |
+
OPENAI_MODEL=gpt-4.1-mini
|
| 122 |
+
```
|
| 123 |
+
|
| 124 |
+
5. Run API
|
| 125 |
+
```bash
|
| 126 |
+
uvicorn app.main:app --reload
|
| 127 |
+
```
|
| 128 |
+
|
| 129 |
+
Alternative host-style run:
|
| 130 |
+
```bash
|
| 131 |
+
uvicorn main:app --reload
|
| 132 |
+
```
|
| 133 |
+
|
| 134 |
+
6. Open interactive docs
|
| 135 |
+
- Swagger UI: `http://127.0.0.1:8000/docs`
|
| 136 |
+
|
| 137 |
+
## Example cURL Commands
|
| 138 |
+
|
| 139 |
+
```bash
|
| 140 |
+
curl -X GET "http://127.0.0.1:8000/health"
|
| 141 |
+
```
|
| 142 |
+
|
| 143 |
+
```bash
|
| 144 |
+
curl -X POST "http://127.0.0.1:8000/summarize" \
|
| 145 |
+
-H "Content-Type: application/json" \
|
| 146 |
+
-d '{"text":"FastAPI makes building APIs fast and maintainable.","max_length":20}'
|
| 147 |
+
```
|
| 148 |
+
|
| 149 |
+
```bash
|
| 150 |
+
curl -X POST "http://127.0.0.1:8000/analyze-sentiment" \
|
| 151 |
+
-H "Content-Type: application/json" \
|
| 152 |
+
-d '{"text":"The onboarding flow is confusing and frustrating."}'
|
| 153 |
+
```
|
| 154 |
+
|
| 155 |
+
## Engineering Notes
|
| 156 |
+
|
| 157 |
+
- Sentiment service includes normalization for common label variants (`pos`, `mixed`, etc.) before mapping to strict enum values.
|
| 158 |
+
- Services fail fast when required env vars are missing.
|
| 159 |
+
- Route layer catches exceptions and returns controlled HTTP 500 errors while logging structured failure context.
|
| 160 |
+
|
| 161 |
+
## Recruiter Snapshot
|
| 162 |
+
|
| 163 |
+
This project demonstrates readiness for roles involving:
|
| 164 |
+
|
| 165 |
+
- AI/LLM backend engineering
|
| 166 |
+
- API productization of GenAI features
|
| 167 |
+
- Reliable model-in-the-loop service development
|
| 168 |
+
- Deployable Python service architecture
|
| 169 |
+
|
| 170 |
+
---
|
| 171 |
+
|
| 172 |
+
If you are reviewing this repository for a role, I can also provide a short architecture walkthrough and trade-off discussion (latency, cost, and model reliability choices).
|