Documentation
¶
Overview ¶
ollama implements an API client for the Ollama provider. https://github.com/ollama/ollama/tree/main/docs/api
Index ¶
- type Client
- func (c *Client) DeleteModel(ctx context.Context, model llm.Model) error
- func (c *Client) Embed(ctx context.Context, model llm.Model, messages []llm.Message, opts ...llm.Opt) ([]llm.Vector, llm.Usage, error)
- func (c *Client) GetModel(ctx context.Context, name string) (llm.Model, error)
- func (c *Client) ListModels(ctx context.Context) ([]llm.Model, error)
- func (c *Client) LoadModel(ctx context.Context, name string, progress llm.DownloadProgressFn) (llm.Model, error)
- func (*Client) Name() string
- func (c *Client) Ping(ctx context.Context) error
- func (c *Client) Recognize(ctx context.Context, model llm.Model, resource llm.Resource, opts ...llm.Opt) (llm.Document, llm.Usage, error)
- func (c *Client) Self() llm.Provider
- func (c *Client) URL() *url.URL
- func (c *Client) UnloadModel(ctx context.Context, model llm.Model) error
- func (c *Client) Version(ctx context.Context) (string, error)
- func (c *Client) WithoutSession(ctx context.Context, model llm.Model, messages []llm.Message, tools []llm.Tool, ...) (llm.Message, llm.Usage, error)
- type Model
- func (m *Model) Aliases() []string
- func (m *Model) Capabilities() llm.ModelCap
- func (m *Model) Created() time.Time
- func (m *Model) Description() string
- func (m *Model) InputTokenLimit() *uint
- func (m *Model) Meta() map[string]json.RawMessage
- func (m *Model) Name() string
- func (m *Model) OutputTokenLimit() *uint
- func (m *Model) Provider() llm.Provider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
func New ¶
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 ¶
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) ListModels ¶
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) Ping ¶
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) UnloadModel ¶
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) 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
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
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
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
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
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) OutputTokenLimit ¶ added in v0.5.0
OutputTokenLimit is not exposed by Ollama's API.