Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

Coach: Admin-Karte als Setup-Assistent, sichtbarer Einstieg im Plan, Doku-Kapitel auf der Website

Duarte Santosae9d6785ac50
diff --git a/.env.example b/.env.example
index c3b57fbbb..bc16929cd 100644
--- a/.env.example
+++ b/.env.example
@@ -148,8 +148,10 @@ RP_NAME=openGym
# COACH_DISABLED=1
#
# COACH_JOB_TIMEOUT_MS gives a job longer than the default five minutes. Only a
-# local model on a CPU needs it (Ollama on a small box: ten minutes is normal);
-# a hosted API that needs more has a problem. Never goes below one minute.
+# local model on a CPU needs it — and normally only for the first request after
+# the model server restarts (the api pre-warms the rules cache after that; a
+# warm review on a 3B model takes about a minute). A hosted API that needs
+# more has a problem. Never goes below one minute.
#
# COACH_JOB_TIMEOUT_MS=1500000
#
diff --git a/docs/AI_COACH.md b/docs/AI_COACH.md
index 1fff4e693..eb0c1065d 100644
--- a/docs/AI_COACH.md
+++ b/docs/AI_COACH.md
@@ -75,6 +75,33 @@ A key, a model and the account binding described below belong to the provider th
entered for. Switching chips does not clear them: the Anthropic key is still there when you
come back from trying Gemini, and each chip shows a mark when it holds one.
+#### Picking and changing models
+
+The model field is never a guess: **List models** asks the endpoint what it actually serves.
+For an Ollama box that means the admin decides what exists — `ollama pull` anything the
+hardware can hold and it appears in the picker on the next refresh; nothing in openGym pins
+you to a blessed list. The choice is remembered **per provider**, so trying a cloud model for
+a week and coming back to the local one restores exactly what was set before.
+
+#### Performance on a small box
+
+The Coach's rules ride as a byte-identical system prompt, so a llama.cpp/Ollama endpoint can
+keep them in its prefix cache and only ever re-process the payload — and the api warms that
+cache itself at boot and every half hour, so the expensive first read happens off everyone's
+clock. Measured on a 4-core, no-GPU VM with `qwen2.5:3b`: a review costs about **a minute**
+warm, versus ~8 minutes before the cache and slimmer payload existed. Three things keep it
+that way:
+
+- `OLLAMA_KEEP_ALIVE=-1` and `OLLAMA_NUM_PARALLEL=1` on the Ollama side — an unloaded model
+ takes its cache with it, and parallel slots split it.
+- Give the container room. A ~3B model at Q4 lives happily in 4 GB; a 4B model squeezed into
+ the same limit does not fail, it *thrashes* — weights fall out of the page cache and
+ generation drops to ~1 token/s. On a 4–6 GB box, smaller and comfortable wins.
+- The endpoint is sent a **JSON schema** with each request (structured outputs), so the shape
+ of the answer is enforced while it is generated and the repair round is rarely needed.
+ Servers that reject schemas get plain JSON mode automatically, then no JSON mode — the
+ validator is the gate either way.
+
### With a runtime in the container (Claude Agent SDK, Codex CLI)
**1. Build the image that has an AI runtime in it.** The default image deliberately has none:
@@ -231,11 +258,12 @@ is a provider problem rather than a prompting problem, and a retry loop against
is a bad way to find that out.
A job is given five minutes by default, which is generous for any hosted API. A model running
-on a CPU behind the compatible endpoint can need more — a 3B model with an 8k prompt takes ten
-minutes on a small VM — so `COACH_JOB_TIMEOUT_MS` in `.env` raises it (never below one
-minute); the api's own HTTP client waits as long as the job, and the chat says "this can take a
-while" rather than promising minutes when the endpoint is a local one. The phone's BYOK mode
-does the same on its own: a local endpoint gets 25 minutes there.
+on a CPU behind the compatible endpoint can need more — with a warm cache a 3B model answers
+in about a minute, but the first job after the model loads pays the full prompt once — so
+`COACH_JOB_TIMEOUT_MS` in `.env` raises the budget (never below one minute); the api's own
+HTTP client waits as long as the job, and the chat says "this can take a while" rather than
+promising minutes when the endpoint is a local one. The phone's BYOK mode does the same on
+its own: a local endpoint gets 25 minutes there.
The Coach may only touch **routines and the week**. Your training log, your weigh-ins and your
settings are not reachable from any change type that exists.
diff --git a/frontend/src/admin.css b/frontend/src/admin.css
index 98d307b67..a1359da52 100644
--- a/frontend/src/admin.css
+++ b/frontend/src/admin.css
@@ -110,3 +110,34 @@
}
.adm-iconbtn{width:44px;height:44px;border-radius:12px;font-size:17px}
.adm-empty{color:var(--label-3);font-size:13.5px;padding:10px 2px}
+
+/* ---------- the Coach before setup: a pitch, not a form ---------- */
+.adm-hero{display:flex;flex-direction:column;align-items:flex-start;gap:4px;padding:6px 2px 2px}
+.adm-hero-av{
+ width:52px;height:52px;border-radius:16px;display:grid;place-items:center;font-size:26px;
+ background:linear-gradient(135deg,var(--acc),color-mix(in srgb,var(--acc) 55%,var(--teal)));
+ color:var(--on-acc);margin-bottom:8px;box-shadow:0 8px 24px -8px color-mix(in srgb,var(--acc) 55%,transparent)
+}
+.adm-hero h2{margin:0 0 4px;font-size:22px;letter-spacing:-.022em}
+.adm-hero p{margin:0 0 14px;font-size:14px;line-height:1.5;color:var(--label-2)}
+.adm-hero-feats{display:grid;gap:10px;margin-bottom:18px}
+.adm-hero-feats>div{display:flex;gap:11px;align-items:flex-start}
+.adm-hero-feats .icn{color:var(--acc);font-size:18px;flex:none;margin-top:2px}
+.adm-hero-feats span{font-size:13.5px;line-height:1.45;color:var(--label-2)}
+.adm-hero-feats b{color:var(--label);font-weight:600}
+.adm-hero .btn{width:100%}
+
+/* ---------- setup progress ---------- */
+.adm-progress{height:5px;border-radius:99px;background:var(--surface-2);overflow:hidden;margin:0 0 10px}
+.adm-progress i{display:block;height:100%;border-radius:99px;background:var(--acc);transition:width var(--med) var(--ease)}
+
+/* ---------- provider chips: clearly idle vs. clearly chosen ---------- */
+.adm-chips .chip{
+ background:var(--surface-2);border:1.5px solid transparent;color:var(--label);
+ font-weight:500;text-transform:none
+}
+.adm-chips .chip.on{background:var(--acc-soft);border-color:var(--acc);color:var(--acc);font-weight:600}
+.adm-chips .chip:active{transform:scale(.97)}
+
+/* a finished step's summary reads as a receipt, not a control */
+.adm-step.done>summary .adm-step-t span{color:var(--acc)}
diff --git a/frontend/src/index.css b/frontend/src/index.css
index 9735d0e33..80176b8dd 100644
--- a/frontend/src/index.css
+++ b/frontend/src/index.css
@@ -990,3 +990,21 @@ h4.sec{
.exmedia img{height:380px}
.hm-wrap{display:flex;flex-direction:column;align-items:center}
}
+
+/* ------------------------------------------------- the Coach entry on Plan -- */
+.coach-cta{
+ display:flex;align-items:center;gap:13px;width:100%;text-align:left;
+ margin-bottom:12px;padding:14px 16px;border-radius:var(--r-card);
+ background:linear-gradient(135deg,var(--acc-soft),color-mix(in srgb,var(--acc) 6%,var(--surface)));
+ border:1px solid color-mix(in srgb,var(--acc) 35%,transparent);
+ transition:transform var(--fast),filter var(--fast)
+}
+.coach-cta:active{transform:scale(.985);filter:brightness(1.06)}
+.coach-cta-av{
+ width:42px;height:42px;border-radius:13px;flex:none;display:grid;place-items:center;font-size:21px;
+ background:var(--acc);color:var(--on-acc);box-shadow:0 6px 18px -6px color-mix(in srgb,var(--acc) 60%,transparent)
+}
+.coach-cta-t{flex:1;min-width:0;display:flex;flex-direction:column;gap:1px}
+.coach-cta-t b{font-size:17px;font-weight:600;letter-spacing:-.015em;color:var(--label)}
+.coach-cta-t span{font-size:13px;color:var(--label-2);line-height:1.35}
+.coach-cta-chev{color:var(--acc);font-size:15px;flex:none}
diff --git a/frontend/src/views/AdminCoach.jsx b/frontend/src/views/AdminCoach.jsx
index 247a9e331..1ccb53f44 100644
--- a/frontend/src/views/AdminCoach.jsx
+++ b/frontend/src/views/AdminCoach.jsx
@@ -110,9 +110,30 @@ export default function AdminCoach() {
const step3Done = authed
const step4Done = !!d.model
const step5Done = !!testResult?.ok || !!d.lastSuccess
- // Step numbers only count the steps this provider actually shows.
+ // Step numbers only count the steps this provider actually shows — and like any wizard,
+ // only the first unfinished step stands open; everything done folds to its summary line.
+ const flags = [step1Done, ...(needsEndpoint ? [step2Done] : []), ...(hasCredentialStep ? [step3Done] : []), step4Done, step5Done]
+ const doneCount = flags.filter(Boolean).length
+ const firstTodo = flags.indexOf(false)
let n = 1
+ let idx = 0
const num = () => n++
+ const stepAt = () => { const i = idx++; return { open: i === (firstTodo === -1 ? -1 : firstTodo), key: i + ':' + (i === firstTodo) } }
+
+ // Off = a quiet, optional feature: one clean pitch and one button, no half-dimmed controls.
+ if (!d.enabled) return <div className="card">
+ <div className="adm-hero">
+ <div className="adm-hero-av"><Icon name="sparkles" /></div>
+ <h2>AI Coach</h2>
+ <p>An optional coach that designs training plans and reviews what people actually log. Off right now — nobody sees it anywhere in the app.</p>
+ <div className="adm-hero-feats">
+ <div><Icon name="clipboard" /><span><b>Bring any AI.</b> An API key from Anthropic, OpenAI or Gemini — or a free local model via Ollama.</span></div>
+ <div><Icon name="shield" /><span><b>Private by design.</b> A strict allowlist decides what leaves; every change needs the user's yes and can be undone.</span></div>
+ <div><Icon name="person" /><span><b>Each user decides.</b> Turning it on only makes the Coach available; every person consents for themselves.</span></div>
+ </div>
+ <Button variant="primary" icon="sparkles" disabled={busy} onClick={() => patch({ enabled: true })}>Set up the Coach</Button>
+ </div>
+ </div>
return <div className="card" style={{ borderColor: live ? 'var(--acc)' : undefined }}>
<div className="row between" style={{ marginBottom: 2 }}>
@@ -120,16 +141,18 @@ export default function AdminCoach() {
<Switch checked={!!d.enabled} disabled={busy} onChange={v => patch({ enabled: v })} />
</div>
<div className="adm-status">
- <span className={'adm-pill ' + (!d.enabled ? '' : live ? 'ok' : 'warn')}>{!d.enabled ? 'off' : live ? 'ready' : 'not ready'}</span>
+ <span className={'adm-pill ' + (live ? 'ok' : 'warn')}>{live ? 'ready' : 'not ready'}</span>
<span>{status}</span>
</div>
+ {!live && <div className="adm-progress" aria-hidden="true"><i style={{ width: Math.round(doneCount / flags.length * 100) + '%' }} /></div>}
<div className="adm-lead">
- The Coach designs a training plan and adjusts it from what people log. This switch is the only place it can be turned off for everyone — users decide for themselves whether to use it, but cannot disable it.
+ {live ? 'Users find the Coach under Plan → Coach. This switch is the only place it can be turned off for everyone.'
+ : `${doneCount} of ${flags.length} steps done — finish the open step and the next one unfolds.`}
</div>
{d.enabled && <>
{/* ---------- provider ---------- */}
- <Step n={num()} title="Provider" hint={meta.label || 'Which AI answers the Coach'} done={step1Done} open={!step1Done}>
+ <Step n={num()} title="Provider" hint={meta.label || 'Which AI answers the Coach'} done={step1Done} {...stepAt()}>
<div className="adm-hint">Pick who answers. A key or token you save stays with its provider, so you can switch back and forth without pasting it again.</div>
{groups.map(g => !!g.items.length && <div key={g.title} className="adm-group">
<div className="adm-group-t">{g.title}</div>
@@ -144,7 +167,7 @@ export default function AdminCoach() {
</Step>
{/* ---------- endpoint (compatible only) ---------- */}
- {needsEndpoint && <Step n={num()} title="Endpoint" hint={d.baseUrl || 'Where the model runs'} done={step2Done} open={!step2Done}>
+ {needsEndpoint && <Step n={num()} title="Endpoint" hint={d.baseUrl || 'Where the model runs'} done={step2Done} {...stepAt()}>
<div className="adm-hint">The address of any server that speaks OpenAI's chat API: <b>Ollama</b>, <b>LM Studio</b>, <b>vLLM</b>, <b>OpenRouter</b>, or a gateway of your own. Just the base — no <code>/v1</code>, no key in the URL.</div>
<div className="adm-field">
<label>Base URL</label>
@@ -155,14 +178,14 @@ export default function AdminCoach() {
</Step>}
{/* ---------- credential ---------- */}
- {hasCredentialStep && <Step n={num()} title="Credential" hint={credentialHint(d.auth, meta)} done={step3Done} open={!step3Done}>
+ {hasCredentialStep && <Step n={num()} title="Credential" hint={credentialHint(d.auth, meta)} done={step3Done} {...stepAt()}>
<div className="row" style={{ gap: 8, flexWrap: 'wrap', marginBottom: 8 }}>
<CredentialPill auth={d.auth} />
</div>
{authState === 'connected' ? <>
<div className="adm-hint">Connected{d.auth.account ? ' as ' + d.auth.account : ''} via {credentialLabel(d.auth.type)}{d.auth.connectedAt ? ' · added ' + rel(d.auth.connectedAt) : ''}. The key is stored encrypted and is never shown again.</div>
<div className="adm-actions">
- {meta.apiKey && <Button size="sm" icon="lock" disabled={busy}
+ {meta.apiKey && <Button size="sm" variant="tinted" icon="lock" disabled={busy}
onClick={() => openSheet(close => <ApiKeySheet close={close} onDone={load} label={meta.label} placeholder={meta.keyPlaceholder} optional={meta.keyOptional} />)}>Replace key</Button>}
<Button size="sm" danger disabled={busy} onClick={disconnect}>Remove</Button>
</div>
@@ -185,7 +208,7 @@ export default function AdminCoach() {
</Step>}
{/* ---------- model ---------- */}
- <Step n={num()} title="Model" hint={d.model || (meta.defaultModel ? 'default: ' + meta.defaultModel : 'not chosen yet')} done={step4Done} open={!step4Done}>
+ <Step n={num()} title="Model" hint={d.model || (meta.defaultModel ? 'default: ' + meta.defaultModel : 'not chosen yet')} done={step4Done} {...stepAt()}>
<div className="adm-hint">{meta.http
? 'Which model the provider should use. "List models" asks the provider for its current list, so nothing here goes stale.'
: 'Optional. Leave it empty to use the runtime\'s own default.'}</div>
@@ -201,17 +224,20 @@ export default function AdminCoach() {
onBlur={e => e.target.value !== (d.models?.[d.provider] || '') && patch({ model: e.target.value })} />}
</div>
{meta.http && <div className="adm-actions">
- <Button size="sm" disabled={busy} onClick={loadModels}>{models ? 'Refresh list' : 'List models'}</Button>
+ <Button size="sm" variant="tinted" icon="reset" disabled={busy} onClick={loadModels}>{models ? 'Refresh list' : 'List models'}</Button>
{models && models.length ? <span className="dim small" style={{ alignSelf: 'center' }}>{models.length} served by the provider</span> : null}
</div>}
</Step>
{/* ---------- test ---------- */}
- <Step n={num()} title="Test" hint={step5Done ? 'passed' : 'one real round trip, no user data'} done={step5Done} open={!step5Done || !!testResult}>
+ <Step n={num()} title="Test" hint={step5Done ? 'passed' : 'one real round trip, no user data'} done={step5Done} {...stepAt()} forceOpen={!!testResult}>
<div className="adm-hint">Sends one tiny question to the provider and checks the answer. No training data is involved. Do this after every change above.</div>
<div className="adm-actions">
<Button size="sm" variant="primary" icon="check" disabled={busy || !authed || !hasEndpoint} onClick={test}>Test the Coach</Button>
</div>
+ {(!authed || !hasEndpoint) && <div className="adm-hint" style={{ margin: '6px 0 0' }}>
+ {!hasEndpoint ? 'Finish the Endpoint step first.' : 'Finish the Credential step first.'}
+ </div>}
{testResult && <div className={'adm-result ' + (testResult.pending ? '' : testResult.ok ? 'ok' : 'bad')}>
{testResult.pending ? 'Asking the provider…'
: testResult.ok ? <><b>Passed</b>{testResult.version ? 'Provider: ' + testResult.version : 'The provider answered as expected.'}</>
@@ -294,8 +320,9 @@ export default function AdminCoach() {
/* ---------------------------------- pieces ---------------------------------- */
-function Step({ n, title, hint, done, open, children }) {
- return <details className={'adm-step ' + (done ? 'done' : 'todo')} open={open}>
+function Step({ n, title, hint, done, open, forceOpen, children }) {
+ // `key` remounts the <details> when the wizard advances, so the next step unfolds itself.
+ return <details className={'adm-step ' + (done ? 'done' : 'todo')} open={open || forceOpen}>
<summary>
<span className="adm-num">{done ? <Icon name="check" /> : n}</span>
<span className="adm-step-t"><b>{title}</b><span>{hint}</span></span>
@@ -329,7 +356,7 @@ const credentialLabel = type => ({
// The failure classes jobs.js emits, in words an operator can act on.
const failureTitle = cls => ({
- timeout: 'The provider took too long (over 5 minutes)',
+ timeout: 'The provider took longer than the job budget (COACH_JOB_TIMEOUT_MS, default 5 minutes)',
missing: 'The provider runtime or key is missing',
auth: 'The provider rejected the credential',
provider: 'The provider returned an error',
diff --git a/frontend/src/views/Plan.jsx b/frontend/src/views/Plan.jsx
index a429d240e..2594e28fb 100644
--- a/frontend/src/views/Plan.jsx
+++ b/frontend/src/views/Plan.jsx
@@ -35,12 +35,14 @@ export default function Plan() {
<div><h1>{t('Plan')}</h1><div className="sub">{t('Your weekly routine')}</div></div>
<button className="iconbtn" onClick={planToolsSheet} aria-label={t('Share your plan')} title={t('Share your plan')}><Icon name="upload" /></button>
</div>
- {showCoach && <div className="list" style={{ marginBottom: 10 }}>
- <Row icon="sparkles" iconTint="var(--acc)" accessory="chevron"
- title={t('Coach')}
- subtitle={t('Plan design and reviews, from your own training')}
- onClick={() => nav('/coach')} />
- </div>}
+ {showCoach && <button className="coach-cta" onClick={() => nav('/coach')}>
+ <span className="coach-cta-av"><Icon name="sparkles" /></span>
+ <span className="coach-cta-t">
+ <b>{t('Coach')}</b>
+ <span>{t('Plan design and reviews, from your own training')}</span>
+ </span>
+ <Icon name="chevronRight" className="coach-cta-chev" />
+ </button>}
<div className="cols"><div>
<h4 className="sec">{t('Week schedule')}</h4>
diff --git a/website/docs.html b/website/docs.html
index 11948076e..2791c9295 100644
--- a/website/docs.html
+++ b/website/docs.html
@@ -139,28 +139,92 @@ docker compose up -d</code></pre>
<a href="https://gitlab.com/DuarteSantos8/opengym/-/blob/main/mcp/README.md" rel="noopener">mcp/README.md</a>.</p>
<h2 id="coach">Let an AI coach write your plan</h2>
- <p>Separate from the read-only bridge above, openGym has an optional <b>AI Coach</b> that can
- design a training plan and, later, review what you actually logged and propose changes to
- it. Answer a few questions — goal, days a week, session length, equipment, anything to work
- around — and it builds a week of routines. Every suggestion carries the evidence behind it,
- you approve or reject each one, and you can undo the last set of changes.</p>
- <p>It is <b>off by default</b>. An admin turns it on in <b>Settings → Admin → AI Coach</b>,
- picks a provider and pastes a key: <b>Anthropic</b>, <b>OpenAI</b>, <b>Google Gemini</b>, or
- any <b>OpenAI-compatible endpoint</b> — Ollama or LM Studio on your own LAN, vLLM,
- OpenRouter. These speak plain HTTPS and need nothing beyond the default image. Only the
- Claude Agent SDK and the Codex CLI need the bigger build:</p>
- <pre><code>API_TARGET=coach docker compose up -d --build api</code></pre>
- <p>On the phone app, <b>Settings → AI Coach</b> offers two ways in: pair the phone with your
- self-hosted instance and the Coach runs there, or bring your own API key and the phone calls
- the provider directly, key in the platform's secure storage.</p>
- <p>It runs on <b>your</b> server under <b>your</b> account — there is no openGym
- service in the middle, and nothing is sent anywhere until you ask it for something. What
- leaves the server is a by-name allowlist (your plan, your logged sets, body weight if you
- track it) under a pseudonym; your name, sign-in details and other profiles never do. What
- comes back can only touch routines and your weekly schedule, and is applied on your device
- after you approve it.</p>
- <p>The Coach is not a doctor or a physiotherapist. If something hurts, ask a professional.
- Full details, including exactly what is sent and how credentials are stored:
+ <p>Separate from the read-only bridge above, openGym has an optional <b>AI Coach</b>. Answer a
+ few questions — goal, days a week, session length, equipment, anything to work around — and
+ it designs a week of routines. Later it reviews what you actually logged and proposes
+ changes; you can also ask it to look at <b>one workout</b> (a debrief: a score, what went
+ well, what to watch, what to do next time) or to <b>improve a single routine</b> and leave
+ the rest alone. If the admin allows it and at least three people opt in, it can show
+ anonymous medians so you can see how you sit against the others on your instance.</p>
+
+ <h3>How it works</h3>
+ <p>The Coach is a chat. The first visit is a short intake, one question per screen; after
+ that, every request works the same way:</p>
+ <ol>
+ <li>The server builds a JSON payload from a <b>by-name allowlist</b>: your plan, the sets
+ you logged in the review window, weigh-ins, your intake answers, and a few preferences —
+ under a pseudonym. Your name, e-mail, passkeys and everyone else's data are not in it,
+ by construction: fields are copied in one by one, nothing is passed through.</li>
+ <li>That payload goes to the provider <b>you</b> configured — there is no openGym service in
+ the middle.</li>
+ <li>The answer is parsed and <b>validated against a closed list of change types</b> (add,
+ remove or swap an exercise, sets, reps, schedule, progression policy…). An answer that
+ names an exercise that doesn't exist, invents a change type, or breaks a rule is
+ refused — it gets exactly one repair round, then the job fails rather than guessing.</li>
+ <li>What survives is shown to you as a card, <b>one checkbox per change</b>, each with the
+ evidence behind it. Nothing touches your plan until you accept it, every proposal stays
+ in the chat history whether you said yes or no, and the last accepted change-set can be
+ undone in one tap.</li>
+ </ol>
+
+ <h3>Providers</h3>
+ <p>It is <b>off by default</b>. An admin turns it on in <b>Settings → Admin → AI Coach</b> and
+ picks who answers:</p>
+ <table class="cfg">
+ <tr><td><b>Anthropic, OpenAI, Google&nbsp;Gemini</b></td><td>Paste an API key from the provider's console. Plain HTTPS from the api process — runs on the default image.</td></tr>
+ <tr><td><b>OpenAI-compatible endpoint</b></td><td>Any server that speaks the Chat Completions API: <b>Ollama</b>, <b>LM Studio</b>, <b>vLLM</b>, <b>OpenRouter</b>, a gateway of your own. A key only if the endpoint wants one. Also the default image.</td></tr>
+ <tr><td><b>Claude Agent SDK / Codex CLI</b></td><td>Run a real AI runtime inside the container — the one case that needs the bigger build: <code>API_TARGET=coach docker compose up -d --build api</code></td></tr>
+ </table>
+
+ <h3 id="coach-local">Run it fully local — no cloud, no cost</h3>
+ <p>A model on your own hardware is just the compatible endpoint with no key. The usual way is
+ an Ollama container next to openGym:</p>
+ <pre><code># docker-compose.yml — add next to the openGym services (same file = same network)
+ ollama:
+ image: ollama/ollama
+ restart: unless-stopped
+ volumes:
+ - ./data/ollama:/root/.ollama
+ environment:
+ - OLLAMA_KEEP_ALIVE=-1 # keep the model (and its prompt cache) loaded
+ - OLLAMA_NUM_PARALLEL=1
+ mem_limit: 4g</code></pre>
+ <pre><code>docker exec -it &lt;ollama container&gt; ollama pull qwen2.5:3b</code></pre>
+ <p>Then in <b>Settings → Admin → AI Coach</b>: provider <b>OpenAI-compatible endpoint</b> →
+ Base URL <code>http://ollama:11434</code> → <b>List models</b> → pick the model →
+ <b>Test the Coach</b>. That's the whole setup.</p>
+ <p><b>Any model you can pull, you can use.</b> <code>ollama pull</code> whatever you like and
+ it appears under <i>List models</i> — the admin is free to run anything the box can hold,
+ and each provider remembers its own model choice, so switching around never loses one.
+ Honest sizing, from measuring exactly this on a small box:</p>
+ <ul>
+ <li>A <b>~3B model at Q4</b> (like <code>qwen2.5:3b</code>) fits a 4–6&nbsp;GB container and
+ answers a review in <b>about a minute</b> on a 4-core CPU once its cache is warm.</li>
+ <li>A <b>4B model needs ~6&nbsp;GB+</b> for its container. Squeezed into less, it doesn't
+ fail — it thrashes, generating at ~1 token/second. Smaller and comfortable beats bigger
+ and swapping.</li>
+ <li>The <b>first request after a restart is slow once</b>: the model loads and reads the
+ Coach's rules. The api pre-warms that cache at boot and every half hour, so in practice
+ people hit the warm path.</li>
+ <li>On a genuinely slow box, raise the job budget with <code>COACH_JOB_TIMEOUT_MS</code>
+ in <code>.env</code>.</li>
+ </ul>
+ <p>A GPU machine elsewhere on your LAN works the same way: run Ollama or LM Studio there and
+ point the Base URL at it, e.g. <code>http://192.168.1.50:11434</code>.</p>
+
+ <h3>On the phone</h3>
+ <p><b>Settings → AI Coach</b> offers two ways in: pair the phone with your self-hosted
+ instance and the Coach runs there under the rules above, or bring your own API key and the
+ phone calls the provider directly — same allowlist, same validator, key in the platform's
+ secure storage, ten runs a day.</p>
+
+ <h3>Privacy and limits</h3>
+ <p>Before anyone uses it, a consent screen lists exactly which categories of data leave the
+ server — generated from the same module that builds the payloads, so it cannot drift from
+ what actually happens. The admin can cap runs per person and per instance per day, and
+ <code>COACH_DISABLED=1</code> in the environment switches the feature off harder than any
+ toggle. The Coach is not a doctor or a physiotherapist — if something hurts, ask a
+ professional. Full details, including exactly what is sent and how credentials are stored:
<a href="https://gitlab.com/DuarteSantos8/opengym/-/blob/main/docs/AI_COACH.md" rel="noopener">docs/AI_COACH.md</a>.</p>
<h2 id="import">Import your training history</h2>