ollama

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

ollama implements an API client for ollama https://github.com/ollama/ollama/blob/main/docs/api.md

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithInsecure

func WithInsecure() llm.Opt

Pull Model: Allow insecure connections for pulling models.

func WithKeepAlive

func WithKeepAlive(v time.Duration) llm.Opt

Embeddings & Chat: Controls how long the model will stay loaded into memory following the request.

func WithOption

func WithOption(key string, value any) llm.Opt

Embeddings & Chat: model-specific options.

func WithPullStatus

func WithPullStatus(fn func(*PullStatus)) llm.Opt

Pull Model: Stream the response as it is received.

func WithTruncate

func WithTruncate() llm.Opt

Embeddings: Does not truncate the end of each input to fit within context length. Returns error if context length is exceeded.

Types

type Client

type Client struct {
	*client.Client
}

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"

func (*Client) CopyModel

func (ollama *Client) CopyModel(ctx context.Context, source, destination string) error

Copy a local model by name

func (*Client) DeleteModel

func (ollama *Client) DeleteModel(ctx context.Context, name string) error

Delete a local model by name

func (*Client) GenerateEmbedding

func (ollama *Client) GenerateEmbedding(ctx context.Context, name string, prompt []string, opts ...llm.Opt) (*EmbeddingMeta, error)

func (*Client) GetModel

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

Get model details

func (*Client) ListModels

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

List models

func (*Client) ListRunningModels

func (ollama *Client) ListRunningModels(ctx context.Context) ([]llm.Model, error)

List running models

func (*Client) LoadModel added in v0.0.3

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

Load a model into memory

func (*Client) Model added in v0.0.3

func (ollama *Client) Model(ctx context.Context, name string) llm.Model

Return the a model by name

func (*Client) Models

func (ollama *Client) Models(ctx context.Context) ([]llm.Model, error)

Agent interface

func (*Client) Name

func (*Client) Name() string

Return the name of the agent

func (*Client) PullModel

func (ollama *Client) PullModel(ctx context.Context, name string, opts ...llm.Opt) (llm.Model, error)

Pull a remote model locally

func (*Client) UnloadModel added in v0.0.3

func (ollama *Client) UnloadModel(ctx context.Context, name string) error

Unload a model from memory

type EmbeddingMeta

type EmbeddingMeta struct {
	Model      string      `json:"model"`
	Embeddings [][]float64 `json:"embeddings"`
	Metrics
}

EmbeddingMeta is the metadata for a generated embedding vector

func (EmbeddingMeta) String

func (m EmbeddingMeta) String() string

type ImageData added in v0.0.6

type ImageData []byte

Data represents the raw binary data of an image file.

type Message added in v0.0.3

type Message struct {
	RoleContent
	Images []ImageData `json:"images,omitempty"`
	Calls  ToolCalls   `json:"tool_calls,omitempty"`
	*ToolResults
}

Message with text or object content

func (*Message) Attachment added in v0.0.10

func (message *Message) Attachment(index int) *llm.Attachment

Return the audio - not supported on ollama

func (*Message) Choice added in v0.0.6

func (message *Message) Choice(index int) llm.Completion

Return the completion

func (Message) Num added in v0.0.3

func (m Message) Num() int

Return the number of completions

func (Message) Role added in v0.0.3

func (m Message) Role() string

Return the current session role

func (Message) Text added in v0.0.3

func (m Message) Text(index int) string

Return the text

func (Message) ToolCalls added in v0.0.3

func (m Message) ToolCalls(index int) []llm.ToolCall

Return the current session tool calls given the completion index. Will return nil if no tool calls were returned.

type Metrics

type Metrics struct {
	TotalDuration      time.Duration `json:"total_duration,omitempty"`
	LoadDuration       time.Duration `json:"load_duration,omitempty"`
	PromptEvalCount    int           `json:"prompt_eval_count,omitempty"`
	PromptEvalDuration time.Duration `json:"prompt_eval_duration,omitempty"`
	EvalCount          int           `json:"eval_count,omitempty"`
	EvalDuration       time.Duration `json:"eval_duration,omitempty"`
}

Metrics

type ModelDetails

type ModelDetails struct {
	ParentModel       string   `json:"parent_model,omitempty"`
	Format            string   `json:"format"`
	Family            string   `json:"family"`
	Families          []string `json:"families"`
	ParameterSize     string   `json:"parameter_size"`
	QuantizationLevel string   `json:"quantization_level"`
}

ModelDetails are the details of the model

type ModelInfo

type ModelInfo map[string]any

ModelInfo provides additional model parameters

type ModelMeta

type ModelMeta struct {
	Name       string       `json:"name"`
	Model      string       `json:"model,omitempty"`
	ModifiedAt time.Time    `json:"modified_at"`
	Size       int64        `json:"size,omitempty"`
	Digest     string       `json:"digest,omitempty"`
	Details    ModelDetails `json:"details"`
	File       string       `json:"modelfile,omitempty"`
	Parameters string       `json:"parameters,omitempty"`
	Template   string       `json:"template,omitempty"`
	Info       ModelInfo    `json:"model_info,omitempty"`
}

ModelMeta is the metadata for an ollama model

type PullStatus

type PullStatus struct {
	Status         string `json:"status"`
	DigestName     string `json:"digest,omitempty"`
	TotalBytes     int64  `json:"total,omitempty"`
	CompletedBytes int64  `json:"completed,omitempty"`
}

PullStatus provides the status of a pull operation in a callback function

func (PullStatus) String

func (m PullStatus) String() string

type Response

type Response struct {
	Model     string           `json:"model"`
	CreatedAt time.Time        `json:"created_at"`
	Done      bool             `json:"done"`
	Reason    string           `json:"done_reason,omitempty"`
	Response  *string          `json:"response,omitempty"` // For completion
	Message   `json:"message"` // For chat
	Metrics
}

Chat Response

func (Response) String

func (r Response) String() string

type RoleContent added in v0.0.3

type RoleContent struct {
	Role    string `json:"role,omitempty"`    // assistant, user, tool, system
	Content string `json:"content,omitempty"` // string or array of text, reference, image_url
}

type ToolCall

type ToolCall struct {
	Type     string           `json:"type"` // function
	Function ToolCallFunction `json:"function"`
}

type ToolCallFunction

type ToolCallFunction struct {
	Index     int            `json:"index,omitempty"`
	Name      string         `json:"name"`
	Arguments map[string]any `json:"arguments,omitempty"`
}

type ToolCalls added in v0.0.6

type ToolCalls []ToolCall

type ToolResults added in v0.0.6

type ToolResults struct {
	Name string `json:"name,omitempty"` // function name - when role is tool
}

Jump to

Keyboard shortcuts

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