Add an ollama provider for local models

Thin constructor over the existing OpenAI-compatible path, same shape
as litellm/openrouter: NewOllamaProvider(baseURL) defaults to Ollama's
local endpoint (http://localhost:11434/v1) and needs no API key, since
Ollama doesn't authenticate requests. Also covers other local servers
that share Ollama's OpenAI-compatible endpoint shape (LM Studio,
llama.cpp's server, vLLM).
This commit is contained in:
sausheong committed 2026-09-07 11:57:56 +08:00
1 parent 897643db18
commit 3b5aadb31f
4 files changed
+84 -12

No files matched your search

+9 -10
View File
@@ -87,9 +87,8 @@ a lot. The package is optimized for the use cases above, not these.
hardened in 1.25. Older toolchains will fail at `go build`.
- **An LLM API key**, depending on which provider(s) you wire in:
`ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, Google ADC for Gemini, or a
LiteLLM/OpenRouter key for those aggregators. For local models, point
`openai.NewOpenAIProviderWithKind` at an Ollama endpoint — no key
required.
LiteLLM/OpenRouter key for those aggregators. For local models,
`ollama.NewOllamaProvider` needs no key at all.
- **Optional: an MCP server** for `tools/mcp` integrations (any
binary that speaks the Model Context Protocol — `npx
@modelcontextprotocol/server-filesystem`, etc.).
@@ -123,7 +122,8 @@ github.com/sausheong/harness/
│ ├── openai/ # OpenAI / OpenAI-compatible / local Ollama
│ ├── gemini/ # Google Gemini via google.golang.org/genai
│ ├── litellm/ # Self-hosted LiteLLM proxy (OpenAI-compatible)
│ └── openrouter/ # OpenRouter aggregator (OpenAI-compatible)
│ ├── openrouter/ # OpenRouter aggregator (OpenAI-compatible)
│ └── ollama/ # Local Ollama server (OpenAI-compatible, no API key)
└── tools/ # Batteries-included concrete tools (each importable separately)
├── file/ # read_file (with vision), write_file, edit_file
├── bash/ # bash (with ExecPolicy: deny | allowlist | full)
@@ -315,12 +315,11 @@ Deliberately not in scope (numbers from the same conceptual list):
`clientcredentials.Config.Client(ctx)`) as `HTTPClient` —
auto-refresh comes for free. Call `Runtime.Close()` to release
sessions.
- **Five providers, one interface.** Anthropic, OpenAI (and
OpenAI-compatible / local Ollama), Gemini, LiteLLM, and OpenRouter ship
built-in — LiteLLM and OpenRouter cost none of that ~300 LOC each,
since both are thin constructors over the existing OpenAI-compatible
path. Adding a genuinely new wire format is implementing
`llm.Provider` (~300 LOC).
- **Six providers, one interface.** Anthropic, OpenAI, Gemini, LiteLLM,
OpenRouter, and Ollama ship built-in — LiteLLM, OpenRouter, and Ollama
cost none of that ~300 LOC each, since all three are thin constructors
over the existing OpenAI-compatible path. Adding a genuinely new wire
format is implementing `llm.Provider` (~300 LOC).
See [`developer.md`](./developer.md) for a step-by-step guide to
building agents on top of Harness, including diagrams of the