mooncak397 Claude Opus 5.5 commited on
Commit ·
44fbd66
1
Parent(s): 9291ded
M6: Dockerfile for a Hugging Face Space (port 7860, 1 worker), server env names, README server section
Browse files- .dockerignore +9 -0
- .env.example +9 -0
- Dockerfile +15 -0
- README.md +11 -0
.dockerignore
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.env
|
| 2 |
+
.venv
|
| 3 |
+
.git
|
| 4 |
+
.claude
|
| 5 |
+
evals
|
| 6 |
+
tests
|
| 7 |
+
web
|
| 8 |
+
docs
|
| 9 |
+
**/__pycache__
|
.env.example
CHANGED
|
@@ -6,3 +6,12 @@ MODEL_JUDGE=gemma-4-31b-it
|
|
| 6 |
# PROVIDER_APP=anthropic
|
| 7 |
# PROVIDER_JUDGE=anthropic
|
| 8 |
# ANTHROPIC_API_KEY=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
# PROVIDER_APP=anthropic
|
| 7 |
# PROVIDER_JUDGE=anthropic
|
| 8 |
# ANTHROPIC_API_KEY=
|
| 9 |
+
|
| 10 |
+
# Server (app/main.py). All optional in dev; set them as Space secrets / variables in production.
|
| 11 |
+
# SESSION_HMAC_KEY= # signs session tokens; unset = random per process
|
| 12 |
+
# ALLOWED_ORIGIN= # the one CORS origin, e.g. the GitHub Pages URL; unset = no browser origin allowed
|
| 13 |
+
# TURNSTILE_SECRET= # Cloudflare Turnstile; unset = check skipped (dev only)
|
| 14 |
+
# RESEND_API_KEY= # unset = /contact answers 503
|
| 15 |
+
# CONTACT_TO= # the one recipient (the Resend account address)
|
| 16 |
+
# CONTACT_FROM= # default: Recruiter assistant <onboarding@resend.dev>
|
| 17 |
+
# Limits (defaults): SESSIONS_PER_IP_HOUR=10 CHAT_PER_IP_HOUR=20 CHAT_PER_DAY=140 CONTACT_PER_IP_DAY=1 CONTACT_PER_DAY=5
|
Dockerfile
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Hugging Face Spaces (Docker SDK): the Space runs the container as user 1000 and routes to port 7860.
|
| 2 |
+
FROM python:3.12-slim
|
| 3 |
+
COPY --from=ghcr.io/astral-sh/uv:0.9 /uv /bin/uv
|
| 4 |
+
RUN useradd -m -u 1000 user
|
| 5 |
+
USER user
|
| 6 |
+
WORKDIR /home/user/app
|
| 7 |
+
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy PATH="/home/user/app/.venv/bin:$PATH"
|
| 8 |
+
COPY --chown=user pyproject.toml uv.lock ./
|
| 9 |
+
RUN uv sync --frozen --no-dev --no-install-project
|
| 10 |
+
COPY --chown=user app ./app
|
| 11 |
+
COPY --chown=user profile ./profile
|
| 12 |
+
COPY --chown=user prompts ./prompts
|
| 13 |
+
EXPOSE 7860
|
| 14 |
+
# exactly 1 worker: chat sessions live in process memory (ADR-010)
|
| 15 |
+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]
|
README.md
CHANGED
|
@@ -10,6 +10,17 @@ Every prompt version will be scored against a fixed golden set, and the score hi
|
|
| 10 |
2. `cp .env.example .env`, then put your Gemini API key (from Google AI Studio) in `.env`.
|
| 11 |
3. `uv run python -m app.cli "Where does Christopher work?"`
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
## Tests
|
| 14 |
|
| 15 |
`uv run pytest` runs without a key and without network access.
|
|
|
|
| 10 |
2. `cp .env.example .env`, then put your Gemini API key (from Google AI Studio) in `.env`.
|
| 11 |
3. `uv run python -m app.cli "Where does Christopher work?"`
|
| 12 |
|
| 13 |
+
## Server (M6)
|
| 14 |
+
|
| 15 |
+
`uv run uvicorn app.main:app --port 7860 --workers 1` (exactly 1 worker: chat history lives in process memory, ADR-010).
|
| 16 |
+
|
| 17 |
+
- `POST /session` with `{}` (or `{"turnstile_token": "..."}` when `TURNSTILE_SECRET` is set) returns `{"token", "expires_in", "turns_left"}`.
|
| 18 |
+
- `POST /chat` with `Authorization: Bearer <token>` and exactly `{"message": "..."}` returns `{"reply", "show_form", "lang", "turns_left"}`. Any other field gives 422, a missing or forged token 401 `invalid_session`, an expired or lost session 401 `session_expired`, more than 1,000 characters 413, a running request for the same session 409.
|
| 19 |
+
- `POST /contact` with the token and `{"email", "message", "turnstile_token"}` sends one email through Resend; 503 when `RESEND_API_KEY` or `CONTACT_TO` is missing.
|
| 20 |
+
- `GET /health` returns the prompt version.
|
| 21 |
+
|
| 22 |
+
Env names are in `.env.example`. The `Dockerfile` is for a Hugging Face Docker Space (port 7860).
|
| 23 |
+
|
| 24 |
## Tests
|
| 25 |
|
| 26 |
`uv run pytest` runs without a key and without network access.
|