Download deploy/huggingface/DEPLOY.md from NAP1320/RotNot: direct link, hf CLI and curl.
- Browser
- Download file 4.07 kB
-
https://huggingface.co/spaces/NAP1320/RotNot/resolve/main/deploy/huggingface/DEPLOY.md
- Command line
-
hf download hf://spaces/NAP1320/RotNot/deploy/huggingface/DEPLOY.md
-
curl -L -o DEPLOY.md https://huggingface.co/spaces/NAP1320/RotNot/resolve/main/deploy/huggingface/DEPLOY.md
Deploying RotNot to a Hugging Face Docker Space
The app ships as a Docker Space (single long-running container β SQLite and the in-memory problem store work as-is). Files involved:
Dockerfile(repo root) β builds and runs the Next.js app on port 7860.scripts/hf-start.shβ migrates + seeds the DB on boot, then starts the app.deploy/huggingface/README.mdβ the Space's rootREADME.md(YAML front matter setssdk: dockerandapp_port: 7860).
1. Create the Space (one time)
Either in the UI β https://huggingface.co/new-space β Docker β Blank β or with the CLI:
pip install -U "huggingface_hub[cli]"
huggingface-cli login # paste a WRITE token
huggingface-cli repo create rotnot --type space --space_sdk docker
2. Push the app
From a clean checkout of this branch:
export HF_TOKEN=hf_xxx # a WRITE token
scripts/deploy-hf.sh NAP1320/RotNot # <user>/<space>
deploy-hf.sh snapshots the current commit, swaps in the front-matter
README.md, and force-pushes it to the Space's main branch. HF then builds
the Dockerfile and boots the app.
3. Set secrets
In the Space: Settings β Variables and secrets
HF_TOKENβ secret. A Hugging Face token (free; create at https://huggingface.co/settings/tokens). Powers all AI features via HF's OpenAI-compatible router β no Anthropic key needed.HF_MODELβ variable (optional). Open instruct model to serve; defaults tometa-llama/Llama-3.1-8B-Instruct. Use a larger model (e.g.meta-llama/Llama-3.3-70B-Instruct) for more reliable JSON output.LICHESS_TOKEN,CHESSCOM_USERNAMEβ optional (chess).
Prefer Anthropic instead? Set
ANTHROPIC_API_KEYand leaveHF_TOKENunset.
The Space rebuilds and starts on https://huggingface.co/spaces/NAP1320/RotNot.
4. (Optional) Let each visitor use their OWN Hugging Face token
The Space-wide HF_TOKEN secret means every visitor's AI usage is billed to the
owner's token. To let anyone bring their own free token instead (and only fall
back to the Space secret when they haven't), implement a per-request key path.
This is not built yet β it's the plan for a follow-up:
- Request-scoped client. Add
getClaude({ hfToken?, hfModel? })(insrc/lib/claude.tsor a newsrc/lib/llm.ts): use the passed token, elseprocess.env.HF_TOKEN, else Anthropic. Keep the existingclaudeexport for back-compat/tests. Have the AI API routes build the client from request headersx-hf-token/x-hf-model(falling back to env). Unit-test the selection logic (injectfetch, asllm-hf.test.tsalready does). - Client headers. In
src/lib/api-client.tsapiFetch, attachx-hf-token/x-hf-modelfromlocalStorage(rotnot:hfToken,rotnot:hfModel) when present; no-op on the server. - Settings UI. In
src/app/settings/page.tsx, add a "Hugging Face" section: a password-type token input, an optional model input, Save (to localStorage), and a "Test connection" button hitting a newGET /api/llm/healthroute that does a tiny completion with the request's token and returns{ ok, model }or an error. - Security. Never log or server-persist a user's token β it lives only in their browser and is sent per request over HTTPS. Say so in the UI. Without any token, AI features degrade gracefully (Coding's written grading already falls back to an offline heuristic).
Acceptance: a visitor pastes their own token in Settings, clicks Test β ok, then the AI features run on their token.
Notes
- Storage is ephemeral: XP/progress resets on rebuild/restart. Attach HF
persistent storage (Settings) and point
DATABASE_URLat the mounted path (e.g.file:/data/dev.db) to keep it. - AI provider:
HF_TOKEN(Hugging Face router) takes priority; setANTHROPIC_API_KEYand leaveHF_TOKENunset to use Anthropic instead. - The build needs no secrets; the token is only read at runtime.