The dataset is currently empty. Upload or create new data files. Then, you will be able to explore them in the Dataset Viewer.

YAML Metadata Warning:empty or missing yaml metadata in repo card

Check out the documentation for more information.

Summarize & Sentiment API

Production-style FastAPI service that exposes LLM-powered text summarization and sentiment analysis endpoints using the OpenAI Responses API.

Built as an AI engineering portfolio project to demonstrate clean API design, schema validation, resilient model-output parsing, and deployment-ready structure.

Why This Project

This repository showcases practical applied-AI backend skills recruiters and hiring managers look for:

  • Designing typed, testable API contracts with Pydantic
  • Integrating LLMs into backend services (not just notebooks)
  • Hardening model outputs with parsing/validation logic
  • Implementing structured JSON logging (structlog) for observability
  • Organizing code into routes, services, and schemas for maintainability

Features

  • Health endpoint for service uptime checks
  • Summarization endpoint with length control
  • Sentiment endpoint returning structured JSON (sentiment, confidence, explanation)
  • Strict validation and normalization of model sentiment labels
  • Environment-driven config (OPENAI_API_KEY, optional OPENAI_MODEL)
  • Render-friendly entrypoint via main.py (uvicorn main:app)

Tech Stack

  • Python
  • FastAPI
  • OpenAI Python SDK (responses.create)
  • Pydantic v2
  • Structlog
  • Uvicorn
  • python-dotenv

Project Structure

.
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ main.py                 # FastAPI app factory, logging setup
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ health.py           # GET /health
β”‚   β”‚   β”œβ”€β”€ summarize.py        # POST /summarize
β”‚   β”‚   └── sentiment.py        # POST /analyze-sentiment
β”‚   β”œβ”€β”€ schemas/
β”‚   β”‚   └── models.py           # Request/response models
β”‚   └── services/
β”‚       β”œβ”€β”€ summarize.py        # LLM summarization logic
β”‚       └── sentiment.py        # LLM sentiment + robust JSON parsing
β”œβ”€β”€ main.py                     # host entrypoint (uvicorn main:app)
└── requirements.txt

API Endpoints

GET /health

Returns status and timestamp.

POST /summarize

Generates a concise summary.

Request body

{
  "text": "Long source text...",
  "max_length": 80
}

Response body

{
  "summary": "Short summary text..."
}

POST /analyze-sentiment

Analyzes sentiment and returns typed output.

Request body

{
  "text": "I loved how smooth this release felt!"
}

Response body

{
  "sentiment": "positive",
  "confidence": 0.93,
  "explanation": "The text expresses clear satisfaction and positive emotion."
}

Local Setup

  1. Clone and enter project
git clone https://github.com/zainabahmed4626-lab/AIEngineeringW1V2.git
cd AIEngineeringW1V2
  1. Create virtual environment
python -m venv .venv
# Windows PowerShell
.venv\Scripts\Activate.ps1
  1. Install dependencies
pip install -r requirements.txt
  1. Configure environment variables
OPENAI_API_KEY=your_openai_key
# Optional
OPENAI_MODEL=gpt-4.1-mini
  1. Run API
uvicorn app.main:app --reload

Alternative host-style run:

uvicorn main:app --reload
  1. Open interactive docs
  • Swagger UI: http://127.0.0.1:8000/docs

Example cURL Commands

curl -X GET "http://127.0.0.1:8000/health"
curl -X POST "http://127.0.0.1:8000/summarize" \
  -H "Content-Type: application/json" \
  -d '{"text":"FastAPI makes building APIs fast and maintainable.","max_length":20}'
curl -X POST "http://127.0.0.1:8000/analyze-sentiment" \
  -H "Content-Type: application/json" \
  -d '{"text":"The onboarding flow is confusing and frustrating."}'

Engineering Notes

  • Sentiment service includes normalization for common label variants (pos, mixed, etc.) before mapping to strict enum values.
  • Services fail fast when required env vars are missing.
  • Route layer catches exceptions and returns controlled HTTP 500 errors while logging structured failure context.

Recruiter Snapshot

This project demonstrates readiness for roles involving:

  • AI/LLM backend engineering
  • API productization of GenAI features
  • Reliable model-in-the-loop service development
  • Deployable Python service architecture

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).

Downloads last month
11