Ollama native adapter
internal/ai/llm/ollama implements llm.Provider over plain net/http:
POST {base}/api/chat with "stream": false, the request schema in
"format", and options.temperature / options.num_predict only when the
request sets them; GET {base}/api/tags for ListModels and Verify. No
Authorization header is sent and redirects are not followed.
Usage comes from prompt_eval_count/eval_count. A schema reply that is
not a JSON object is ErrBadOutput. HTTP 404 on /api/chat is an
ErrProvider naming the configured model, without quoting the body.
Refused connections and timeouts match ErrTimeout and say
"Ollama not reachable at {base}"; a cancelled context stays
context.Canceled. The base URL is required, absolute http or https
(LAN hosts allowed), and may not carry userinfo, a query or a fragment.
Contract tests replay sanitized fixtures adapted from Ollama's public
API docs against httptest servers: success, schema output, model
missing and unreachable host.
Maestro task: 51289131-5abf-48c3-b553-7e3809c09076
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+36
@@ -0,0 +1,36 @@
|
||||
# Ollama adapter fixtures
|
||||
|
||||
These are the native Ollama API response bodies the contract tests in
|
||||
`ollama_test.go` replay. They are **not live captures**. Product AI is tested
|
||||
with fakes and live vendor calls are opt-in, so no request was sent to an
|
||||
Ollama server to make them. Each fixture is a sanitized adaptation of the
|
||||
response shapes in Ollama's public API documentation
|
||||
(<https://github.com/ollama/ollama/blob/main/docs/api.md>):
|
||||
|
||||
- Chat, non-streaming: `POST /api/chat` with `"stream": false`.
|
||||
- Structured outputs: `POST /api/chat` with a JSON schema in `"format"`.
|
||||
- List local models: `GET /api/tags`.
|
||||
- Errors: a JSON `{"error": "..."}` body with a non-2xx status; a model
|
||||
that is not pulled is HTTP 404.
|
||||
|
||||
Sanitizing:
|
||||
|
||||
- Timestamps, durations, sizes, digests and token counts are illustrative
|
||||
values in the documented format, not values from a real server.
|
||||
- Message content is replaced with MealQuest dinner text.
|
||||
- Ollama takes no credentials, so none appear.
|
||||
|
||||
Below, *not in the public example* marks values that were added for a test
|
||||
case and do not come from the documented example.
|
||||
|
||||
| Fixture | Case | Shape | Not in the public example |
|
||||
| --- | --- | --- | --- |
|
||||
| `chat_text.json` | Success | Finished chat message, `done_reason: stop`, `prompt_eval_count` and `eval_count`. | — |
|
||||
| `chat_schema.json` | Schema output | Finished chat message whose content is a JSON object string. | The dinner object. |
|
||||
| `error_model_not_found.json` | Model missing | `{"error": "model \"…\" not found, try pulling it first"}`, served with HTTP 404. | — |
|
||||
| `tags.json` | Model list | `{"models": [...]}` with `name`, `model`, `digest` and `details`. | — |
|
||||
|
||||
The unreachable-host case has no fixture: there is no response to record.
|
||||
The tests close an `httptest` server and dial its address, so the
|
||||
connection is refused, and they hold a reply past a short deadline for the
|
||||
timeout.
|
||||
Reference in New Issue
Block a user