docs: separate opencode vs openlama provider isolation

- opencode (global config) sees marg/fireworks only, no ocp
- openlama (OPENCODE_CONFIG=openlama.json) sees ocp only via enabled_providers
- Verified: opencode run -m ocp/... → Model not found; openlama run -m ocp/... → OK
- openlama launcher sets OPENCODE_CONFIG + NO_PROXY + execs opencode
This commit is contained in:
Atte149 2026-06-19 14:18:14 +03:00
parent c8974d9998
commit 98bbc96bf5
2 changed files with 59 additions and 32 deletions

View file

@ -50,22 +50,35 @@ systemd/ollama-proxy.service — systemd unit
## Интеграция с opencode ## Интеграция с opencode
В `~/.config/opencode/opencode.json` в блоке `provider`: **Два отдельных конфига:** `opencode` видит только marg/fireworks, `openlama` видит только ocp.
- `~/.config/opencode/opencode.json` — глобальный конфиг с `marg` + `fireworks` (без `ocp`)
- `~/.config/opencode/openlama.json` — отдельный конфиг с `ocp` + `"enabled_providers": ["ocp"]`. Содержит те же instructions/mcp/plugins/agent что глобальный, но только провайдер `ocp`.
- `~/.local/bin/openlama` — обёртка, выставляет `OPENCODE_CONFIG=~/.config/opencode/openlama.json` + `NO_PROXY=127.0.0.1,localhost,::1` + `exec opencode "$@"`
openlama.json (ключевая часть):
```json ```json
"ocp": { {
"npm": "@ai-sdk/openai-compatible", "enabled_providers": ["ocp"],
"name": "Ollama Cloud (pool)", "provider": {
"options": { "ocp": {
"baseURL": "http://127.0.0.1:11435/v1", "npm": "@ai-sdk/openai-compatible",
"apiKey": "proxy" "name": "Ollama Cloud (pool)",
}, "options": {
"models": { "baseURL": "http://127.0.0.1:11435/v1",
"gpt-oss:20b": { "name": "gpt-oss:20b" }, "apiKey": "proxy"
"...": { "name": "..." } },
"models": {
"gpt-oss:20b": { "name": "gpt-oss:20b" },
"...": { "name": "..." }
}
}
} }
} }
``` ```
Модель выбирается через `/models` в TUI. Пул не сделан дефолтной моделью. `OPENCODE_CONFIG` мерджится с глобальным конфигом, но `enabled_providers: ["ocp"]` перекрывает глобальный — `marg`/`fireworks` скрыты.
**Модель не сделана дефолтной** — выбирается через `/models` в TUI.
**ВАЖНО: NO_PROXY.** Если в окружении установлен `HTTP_PROXY`/`HTTPS_PROXY` (например `http://127.0.0.1:2080`), opencode (Bun runtime) направит запросы к прокси через HTTP-прокси → 502 Bad Gateway. Нужно явно исключить localhost: **ВАЖНО: NO_PROXY.** Если в окружении установлен `HTTP_PROXY`/`HTTPS_PROXY` (например `http://127.0.0.1:2080`), opencode (Bun runtime) направит запросы к прокси через HTTP-прокси → 502 Bad Gateway. Нужно явно исключить localhost:
```sh ```sh

View file

@ -63,20 +63,38 @@ Configuration flags can be overridden via environment variables in the unit (or
## Use with OpenCode ## Use with OpenCode
Add a custom provider to `~/.config/opencode/opencode.json`: The pool is wired into OpenCode via a **separate config** so that `opencode` and `openlama` expose different providers:
| Command | Providers visible |
|---------|-------------------|
| `opencode` | `marg`, `fireworks` (your defaults) |
| `openlama` | `ocp` only (Ollama Cloud pool) |
### How it works
1. The global config at `~/.config/opencode/opencode.json` contains `marg` + `fireworks`**no `ocp`**.
2. A dedicated config at `~/.config/opencode/openlama.json` contains `ocp` + `"enabled_providers": ["ocp"]`. `OPENCODE_CONFIG` merges with the global config, but `enabled_providers` overrides it so `marg`/`fireworks` are hidden.
3. The `openlama` launcher (at `~/.local/bin/openlama`) sets `OPENCODE_CONFIG`, `NO_PROXY`, and execs `opencode`.
### openlama.json
```json ```json
"ocp": { {
"npm": "@ai-sdk/openai-compatible", "$schema": "https://opencode.ai/config.json",
"name": "Ollama Cloud (pool)", "enabled_providers": ["ocp"],
"options": { "provider": {
"baseURL": "http://127.0.0.1:11435/v1", "ocp": {
"apiKey": "proxy" "npm": "@ai-sdk/openai-compatible",
}, "name": "Ollama Cloud (pool)",
"models": { "options": {
"gpt-oss:20b": { "name": "gpt-oss:20b" }, "baseURL": "http://127.0.0.1:11435/v1",
"gpt-oss:120b": { "name": "gpt-oss:120b" }, "apiKey": "proxy"
"kimi-k2.6": { "name": "kimi-k2.6" } },
"models": {
"gpt-oss:20b": { "name": "gpt-oss:20b" },
"gpt-oss:120b": { "name": "gpt-oss:120b" }
}
}
} }
} }
``` ```
@ -89,22 +107,18 @@ curl -sS http://127.0.0.1:11435/v1/models | jq -r '.data[].id'
### NO_PROXY (important) ### NO_PROXY (important)
If your environment has `HTTP_PROXY`/`HTTPS_PROXY` set (e.g. `http://127.0.0.1:2080`), opencode's Bun runtime will route requests to the proxy *through* the HTTP proxy, resulting in `502 Bad Gateway`. Exclude localhost from proxying: If your environment has `HTTP_PROXY`/`HTTPS_PROXY` set (e.g. `http://127.0.0.1:2080`), opencode's Bun runtime will route requests to the proxy *through* the HTTP proxy, resulting in `502 Bad Gateway`. The `openlama` launcher sets this for you; for manual launches:
```sh ```sh
# ~/.config/environment.d/no-proxy-local.conf NO_PROXY=127.0.0.1,localhost,::1 OPENCODE_CONFIG=~/.config/opencode/openlama.json opencode
NO_PROXY=127.0.0.1,localhost,::1
no_proxy=127.0.0.1,localhost,::1
``` ```
Or launch opencode with `NO_PROXY=127.0.0.1,localhost opencode`.
### `openlama` launcher ### `openlama` launcher
A convenience wrapper is installed at `~/.local/bin/openlama`. It sets `NO_PROXY`/`no_proxy` for localhost, tries to start `ollama-proxy` if it's down, and execs `opencode` with all forwarded args: A convenience wrapper is installed at `~/.local/bin/openlama`. It sets `NO_PROXY`/`no_proxy` for localhost, sets `OPENCODE_CONFIG` to the ocp-only config, tries to start `ollama-proxy` if it's down, and execs `opencode` with all forwarded args:
```sh ```sh
openlama # TUI with ocp available as a provider openlama # TUI with only ocp available
openlama run -m ocp/gpt-oss:120b "hello" # non-interactive, specific model openlama run -m ocp/gpt-oss:120b "hello" # non-interactive, specific model
``` ```