ollama

package
v1.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 18 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

ollama implements an API client for the Ollama provider. https://github.com/ollama/ollama/tree/main/docs/api

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*client.Client
	// contains filtered or unexported fields
}

func New

func New(endPoint string, opts ...client.ClientOpt) (*Client, error)

Create a new client, with an ollama endpoint, which should be something like "http://localhost:11434/api". As with OLLAMA_HOST, an endpoint without a scheme, such as "localhost", uses http and Ollama's default port, 11434, unless it has a port.

func (*Client) DeleteModel

func (c *Client) DeleteModel(ctx context.Context, model llm.Model) error

DeleteModel deletes the model, which must be an Ollama model, from the server

func (*Client) Embed added in v0.5.0

func (c *Client) Embed(ctx context.Context, model llm.Model, messages []llm.Message, opts ...llm.Opt) ([]llm.Vector, llm.Usage, error)

Embed returns a vector for each of the messages, which must be for an Ollama model which embeds, in the same order, and the tokens in their inputs, in one request. A message is embedded by its text, and its image and audio, at most one of each, for a model with vision or audio, such as embeddinggemma-2. A message must have text or media. The request isn't timed out, as a model can take a while to load, but is cancelled with the context.

func (*Client) GetModel

func (c *Client) GetModel(ctx context.Context, name string) (llm.Model, error)

GetModel returns details of the model with the given name.

func (*Client) ListModels

func (c *Client) ListModels(ctx context.Context) ([]llm.Model, error)

ListModels returns the list of models available in the local Ollama registry.

func (*Client) LoadModel

func (c *Client) LoadModel(ctx context.Context, name string, progress llm.DownloadProgressFn) (llm.Model, error)

LoadModel downloads the model with the name, and returns it, or returns it if it's already present. A name without a tag has the default tag, "latest", as Ollama stores and lists the model with it, so the model is returned with its full name, such as "gemma:latest" for "gemma". The progress function, if not nil, is called with the status of the download, and the percentage of its bytes downloaded, as it progresses. The download isn't timed out, as models can be large, but is cancelled with the context.

func (*Client) Name

func (*Client) Name() string

Name returns the provider name

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping checks the connectivity of the client and returns an error if not successful

func (*Client) Recognize added in v0.5.0

func (c *Client) Recognize(ctx context.Context, model llm.Model, resource llm.Resource, opts ...llm.Opt) (llm.Document, llm.Usage, error)

Recognize returns the text in the image, as a document with one page, in Markdown, and its regions, when they're asked for, and the tokens used, and the page. The model must be an Ollama model which sees images, such as deepseek-ocr, which is asked with its own prompt, and recognizes regions. Ollama's models read images, not documents, so a PDF isn't recognized. An image should be large enough for its text to be read, as a model doesn't read small text. The request isn't timed out, as a model can take a while to load, but is cancelled with the context.

func (*Client) Self

func (c *Client) Self() llm.Provider

Self returns the underlying client implementation.

func (*Client) URL added in v0.5.0

func (c *Client) URL() *url.URL

URL returns the client's normalized endpoint

func (*Client) UnloadModel

func (c *Client) UnloadModel(ctx context.Context, model llm.Model) error

UnloadModel unloads the model, which must be an Ollama model, from the server's memory, keeping it stored, with a request to generate with it which keeps it loaded for no time, as Ollama does

func (*Client) Version added in v0.5.0

func (c *Client) Version(ctx context.Context) (string, error)

Version returns the Ollama server's version string.

func (*Client) WithoutSession

func (c *Client) WithoutSession(ctx context.Context, model llm.Model, messages []llm.Message, tools []llm.Tool, stream llm.GeneratorStreamFn, opts ...llm.Opt) (llm.Message, llm.Usage, error)

WithoutSession returns the model's reply to the messages, which must be for an Ollama model, and the tokens used. The model can call the tools, and the reply has its calls. When the stream function isn't nil, the reply is streamed, and the function is called with each piece of its thinking and text as it's generated. The request isn't timed out, as a model can take a while to load and reply, but is cancelled with the context.

type Model added in v0.5.0

type Model struct {
	// contains filtered or unexported fields
}

Model represents a single Ollama model, satisfying the llm.Model interface.

func (*Model) Aliases added in v0.5.0

func (m *Model) Aliases() []string

Aliases returns alternate names for the model, which is its name without its tag, when its tag is the default, "latest", such as "llama3.2" for "llama3.2:latest", as Ollama uses the default tag when there's none

func (*Model) Capabilities added in v0.5.0

func (m *Model) Capabilities() llm.ModelCap

Capabilities returns what Ollama reports the model can do, which is none of them when it didn't report the model's capabilities, as when it couldn't be shown. It doesn't report OCR, which a model such as deepseek-ocr has, by its name, and a model which doesn't see images hasn't, nor transcription or translation.

func (*Model) Created added in v0.5.0

func (m *Model) Created() time.Time

Created returns when the model was last pulled or modified locally - Ollama has no separate "created" timestamp.

func (*Model) Description added in v0.5.0

func (m *Model) Description() string

Description summarises the model's family and size, e.g. "llama - 3B params, Q4_K_M quantization". Ollama has no separate human-readable description field, so this is derived from Details.

func (*Model) InputTokenLimit added in v0.5.0

func (m *Model) InputTokenLimit() *uint

InputTokenLimit returns the model's context length, if Ollama reported one in model_info. The context length of the model's family, such as "llama.context_length", is preferred, as model_info can have more than one, such as for a vision model's projector. Otherwise any context length is used, in order of key.

func (*Model) Meta added in v0.5.0

func (m *Model) Meta() map[string]json.RawMessage

Meta returns provider-specific metadata: the model's "details" object, plus "model_info" if the API returned it (only for a single model fetched via GetModel, not for ListModels' summary entries).

func (*Model) Name added in v0.5.0

func (m *Model) Name() string

Name returns the model name, e.g. "llama3.2:latest"

func (*Model) OutputTokenLimit added in v0.5.0

func (m *Model) OutputTokenLimit() *uint

OutputTokenLimit is not exposed by Ollama's API.

func (*Model) Provider added in v0.5.0

func (m *Model) Provider() llm.Provider

Provider returns the client this model came from.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL