M11 solution
The expected, fully-commented artifacts for M11's lab. Peek only after you've tried.
| File | What it is |
|---|---|
app.py |
The deployable service: FastAPI with /health and POST /chat, request validation, and latency + token-usage logging. |
Dockerfile |
Packages the app into a container (Python 3.12 base, deps installed, uvicorn entrypoint). |
.dockerignore |
Keeps .env and clutter out of the image. |
requirements.txt |
The app's own dependencies (what the Dockerfile installs). |
Run it
Local (no Docker):
pip install -r requirements.txt
uvicorn app:app --reload # → http://127.0.0.1:8000/docs
docker build -t ai-app .
docker run -p 8000:8000 --env-file .env ai-app
ANTHROPIC_API_KEY in .env. The key is passed at run time, never baked in.
How this was verified
- FastAPI app verified for real with FastAPI's
TestClient(the model call mocked, no key):GET /health→200 {"status":"ok"};POST /chat {"message":...}→200 {"reply":...}with alatency=… in_tokens=… out_tokens=…log line; a malformed body →422(validation works). - Dockerfile checked structurally: Python
3.12-slimbase, deps installed before code (layer caching), uvicorn entrypoint,.envexcluded via.dockerignore, and no key baked in (passed at run time with--env-file).
Docker build/run not executed here (no Docker daemon in the build sandbox), pilot
docker build/docker runon a machine with Docker. The live/chatcall also needs a real key (the learner's run). No API key or billed call was used here.