Use Ollama when you want funcai to call local models through the Ollama API.
import { createAiFn } from "funcai";
import { ollama } from "funcai/providers/ollama";
const ai = createAiFn({
provider: ollama(),
});Install and start Ollama, then pull a model:
ollama pull gemma4:latestThe default base URL is:
http://127.0.0.1:11434
Use the default local server:
const ai = createAiFn({
provider: ollama(),
});Or point at another host:
const ai = createAiFn({
provider: ollama({
baseURL: "http://192.168.2.188:11434",
}),
});Optional advanced fields:
ollama({
baseURL: "http://127.0.0.1:11434",
apiKey: "optional-proxy-key",
headers: { "x-local-run": "dev" },
fetch: customFetch,
});Ollama model IDs are local strings, so OllamaModelId is intentionally open:
const classify = ai.fn({
model: "gemma4:latest",
// ...
});Set OLLAMA_MODEL in examples when your local model ID differs.
All funcai calls use schema-backed object generation. Model reliability depends on the local model and quantization. Strong instruction-following models with native JSON support are the best fit.
For multimodal examples, use a model that actually accepts image input through your installed Ollama version.
Start Ollama, pull the model, then run:
Set OLLAMA_BASE_URL and OLLAMA_MODEL, then run pnpm exec vitest run --config vitest.e2e.config.ts tests/e2e/ollama-live.test.ts.
Examples:
Set OLLAMA_BASE_URL and OLLAMA_MODEL, then run pnpm -C examples ollama:vision.
- Connection refused: start Ollama and confirm the base URL does not include
/v1. - Model not found: run
ollama pull <model>or use an installed model fromollama list. - Schema parse failures: use a stronger model, simplify the schema, add few-shots, or lower prompt ambiguity.
- Multimodal input fails: confirm the selected model and installed Ollama version support image input.