Skip to content

Ollama

Ollama provider for local model inference. Ollama exposes an OpenAI-compatible API and requires no authentication by default.

Setup

bash
go get github.com/zendev-sh/goai@latest
go
import "github.com/zendev-sh/goai/provider/ollama"

Ollama must be running locally. Install from ollama.com and pull a model:

bash
ollama pull llama3
ollama serve

No API key is required.

Models

Any model available in Ollama. Common examples:

  • llama3, llama3.2:1b, llama3.2:3b
  • mistral, mixtral
  • codellama
  • nomic-embed-text (embeddings)

Tested Models

Unit tested (mock HTTP server, 2026-03-15): llama3, llama3.2:1b, nomic-embed-text

Usage

Chat

go
model := ollama.Chat("llama3")

result, err := goai.GenerateText(ctx, model, goai.WithPrompt("Hello"))
if err != nil {
    log.Fatal(err)
}
fmt.Println(result.Text)

Embeddings

go
embedModel := ollama.Embedding("nomic-embed-text")

result, err := goai.Embed(ctx, embedModel, "hello world")

Remote Ollama Server

go
model := ollama.Chat("llama3",
    ollama.WithBaseURL("http://192.168.1.100:11434/v1"),
)

Options

OptionTypeDescription
WithBaseURL(url)stringOverride the default http://localhost:11434/v1 endpoint
WithHeaders(h)map[string]stringSet additional HTTP headers
WithHTTPClient(c)*http.ClientSet a custom *http.Client

Notes

  • This is a convenience wrapper around the generic compat provider.
  • Default endpoint: http://localhost:11434/v1.
  • No authentication options (WithAPIKey, WithTokenSource) since Ollama does not require auth by default. For authenticated setups, use the compat provider directly.

Released under the MIT License.