feat(m1): Ollama client, catalog, streaming chat and CLI (T1.1-T1.6)

Add endpoint policy and redirect-safe ephemeral HTTP client, error mapping, catalog cache and version checks, streaming chat with phase timeouts/cancellation, provisional Hy-MT3 prompt/language/request factory, warm-up policy, and sprachmittler-cli models/show/translate. Recapture the 7B fixtures; defer the 1.8B VERIFY items; document ADR-016. Also fix the signature checker's pipefail SIGPIPE issue.
This commit is contained in:
schihei committed 2026-11-26 13:04:22 +01:00
1 parent 7ca5c710ec
commit 26b493e7e5
93 files changed
+3732 -218

No files matched your search

+14 -15
View File
@@ -60,7 +60,7 @@ The final line:
```
- Durations are nanoseconds. Map them into `ChatMetrics` (load, prompt eval, eval, total; token counts).
- `done_reason`: `"stop"` = normal end; `"length"` = hit `num_predict` → warning `truncated`, Replace disabled by default. Treat any other value as `"stop"` but log it at `.info`. **VERIFY** the full set of values.
- `done_reason`: `"stop"` = normal end; `"length"` = hit `num_predict` → warning `truncated`, Replace disabled by default. Observed values: `"stop"` and `"length"`; a client-aborted stream returns no final object. Treat any other value as `"stop"` but log it at `.info`.
- A line `{"error":"…"}` may appear mid-stream. Map it with §5 and stop.
### 1.2 Decoding rules
@@ -75,8 +75,7 @@ The final line:
| Phase | Default | Meaning |
|---|---|---|
| connect | 3 s | TCP connect plus TLS |
| firstToken | 120 s | request sent → first `message.content` byte; includes cold model load |
| connect + firstToken | 120 s | TCP/TLS connect plus request sent → first `message.content` byte; includes cold model load. `URLSession` has no separate connect hook, so the two share this budget. |
| idle | 20 s | gap between lines once streaming has started |
| totalPerChunk | 180 s | hard cap per chunk |
@@ -86,7 +85,7 @@ All injectable via a `Clock` for tests.
### 2.1 `GET /api/version`
`{"version":"0.40.18"}`. The minimum supported version is recorded in T1.1 and checked in onboarding.
`{"version":"0.40.18"}`. The minimum supported version is **0.40.0**, checked in onboarding and by the catalog.
### 2.2 `GET /api/tags`
@@ -111,7 +110,7 @@ Request `{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M"}`. Verified fields:
| `model_info` | `hunyuan-dense.context_length = 262144` | Informational; the card's translation context is 8192 |
| `license` | `null` in Ollama | Show the Hugging Face licence (Apache-2.0) in Settings |
**VERIFY** for the 1.8B tag and for future versions.
**VERIFY** for the 1.8B tag and for future versions. The 1.8B is not installed; its `/api/show` fields are deferred to T2.7/T7.4.
### 2.4 `GET /api/ps`
@@ -123,7 +122,7 @@ Used by diagnostics and the evaluation harness for resident memory. Not polled b
## 3. Warm-up
Optional (`warmUpOnLaunch`, local endpoint only): send `POST /api/chat` with the selected model, a fixed synthetic sentence (for example `Hello.`), `num_predict: 8`, and discard the output. **Never** use the user's text for warm-up. The request shape is the same as §1.
Optional (`warmUpOnLaunch`, local endpoint only): send `POST /api/chat` with the selected model, a fixed synthetic sentence (for example `Hello.`), `num_predict: 8`, and discard the output. **Never** use the user's text for warm-up. The request shape is the same as §1. A warm-up with `num_predict: 8` returns `done_reason: "length"`; discard it.
## 4. Option mapping
@@ -142,7 +141,7 @@ The names matter: Ollama does not read `repetition_penalty` or `max_tokens`. Do
| Condition | HTTP / transport | Map to |
|---|---|---|
| Connection refused / host unreachable | `URLError.cannotConnectToHost`, `.cannotFindHost`, connect timeout | `ollamaUnreachable` |
| Connection refused / host unreachable | `URLError.cannotConnectToHost`, `.cannotFindHost` | `ollamaUnreachable` |
| Redirect | 3xx (delegate refuses) | `endpointRejected(.redirect)` |
| Model not installed | typically 404 with body containing `not found` | `modelNotInstalled(model)` |
| Model has no Hy-MT3 adapter | discovery succeeds but name does not match | `noAdapter(model)` |
@@ -150,7 +149,7 @@ The names matter: Ollama does not read `repetition_penalty` or `max_tokens`. Do
| Out of memory / model failed to load | 500 with message containing `memory` or `load` | `server(status, message)` with recovery "Use the smaller 1.8B model or close other apps" |
| Context too small / prompt truncated | 400 or `done_reason: "length"` | `badRequest` / warning `truncated` |
| Error line mid-stream | `{"error":"…"}` | classify by message, else `server(0, message)` |
| First-token, idle or total timeout | timer | `timeout(phase)`; one retry before any delta |
| Connect, first-token, idle or total timeout | timer | `timeout(phase)`; one retry before any delta |
| Task cancelled | `CancellationError` / `URLError.cancelled` | `cancelled`; not an error for the UI |
| Other 4xx/5xx | status | `server(status, message)` |
@@ -177,17 +176,17 @@ Rules: synthetic inputs only; keep each fixture under 200 KB; never record priva
- The GGUF metadata reports `context_length = 262144`, but the model card documents **8192** for translation. Set `num_ctx: 8192`; do not rely on Ollama's default, which may be smaller and silently truncate.
- With `num_ctx: 8192`, `ollama ps` reported **6.49 GB** resident for the 7B Q4_K_M. Budget accordingly on 16 GB Macs.
## 8. Open VERIFY items
## 8. VERIFY status
Resolved on 2026-11-26 (Ollama 0.40.18, digest `262ac792aeb5`, M5 Pro 48 GB):
Verified on 2026-11-26 (Ollama 0.40.18, digest `262ac792aeb5`, M5 Pro 48 GB):
- `done_reason` observed: `stop` and `length` (the truncated fixture with `num_predict: 16` ends with `length`). No `load` value seen.
- `done_reason` observed: `stop` and `length` (the truncated fixture with `num_predict: 16` ends with `length`; `num_predict: 8` also ends with `length`). No `load` value seen. A client-aborted stream returns no final object at all.
- `keep_alive: "0"` unloads the 7B immediately: `/api/ps` showed no model at the first check after the response.
- Cold/first load observed: 0.80 s and 2.05 s in two runs; warm load ~1 ms.
- A `system` message was not sent; v1 does not send one.
- Ollama strips the template's `<|eos|>` from the returned content (observed: yes).
Still open:
Still open / deferred:
- Whether `keep_alive: "0"` fully unloads the model and how quickly `/api/ps` reflects it.
- The 1.8B tag behaviour: capabilities, context, memory, speed, quality.
- The full set of `done_reason` values on other inputs (e.g. an aborted stream).
- The 1.8B tag behaviour (capabilities, context, memory, speed, quality) is deferred to T2.7/T7.4 until that model is installed.
- Other `done_reason` values on future Ollama versions; treat unknown values as `stop` and log them.