Documentation
¶
Overview ¶
ollama implements an API client for ollama https://github.com/ollama/ollama/blob/main/docs/api.md
Index ¶
- func WithInsecure() llm.Opt
- func WithKeepAlive(v time.Duration) llm.Opt
- func WithOption(key string, value any) llm.Opt
- func WithPullStatus(fn func(*PullStatus)) llm.Opt
- func WithTruncate(v bool) llm.Opt
- type Client
- func (ollama *Client) Chat(ctx context.Context, prompt llm.Context, opts ...llm.Opt) (*Response, error)
- func (ollama *Client) CopyModel(ctx context.Context, source, destination string) error
- func (ollama *Client) DeleteModel(ctx context.Context, name string) error
- func (ollama *Client) GenerateEmbedding(ctx context.Context, name string, prompt []string, opts ...llm.Opt) (*EmbeddingMeta, error)
- func (ollama *Client) GetModel(ctx context.Context, name string) (llm.Model, error)
- func (ollama *Client) ListModels(ctx context.Context) ([]llm.Model, error)
- func (ollama *Client) ListRunningModels(ctx context.Context) ([]llm.Model, error)
- func (ollama *Client) Models(ctx context.Context) ([]llm.Model, error)
- func (*Client) Name() string
- func (ollama *Client) PullModel(ctx context.Context, name string, opts ...llm.Opt) (llm.Model, error)
- type Data
- type EmbeddingMeta
- type MessageMeta
- type Metrics
- type ModelDetails
- type ModelInfo
- type ModelMeta
- type PullStatus
- type Response
- type ToolCall
- type ToolCallFunction
- type ToolFunction
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithInsecure ¶
Pull Model: Allow insecure connections for pulling models.
func WithKeepAlive ¶
Embeddings & Chat: Controls how long the model will stay loaded into memory following the request.
func WithOption ¶
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 ¶
Embeddings: Does not truncate the end of each input to fit within context length. Returns error if context length is exceeded.
Types ¶
type Client ¶
func New ¶
Create a new client, with an ollama endpoint, which should be something like "http://localhost:11434/api"
func (*Client) DeleteModel ¶
Delete a local model by name
func (*Client) GenerateEmbedding ¶
func (*Client) ListModels ¶
List models
func (*Client) ListRunningModels ¶
List running models
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 MessageMeta ¶
type MessageMeta struct { Role string `json:"role"` Content string `json:"content,omitempty"` FunctionName string `json:"name,omitempty"` // Function name for a tool result Images []Data `json:"images,omitempty"` // Image attachments ToolCalls []ToolCall `json:"tool_calls,omitempty"` // Tool calls from the assistant }
Chat Message
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 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"` Message MessageMeta `json:"message"` Done bool `json:"done"` Reason string `json:"done_reason,omitempty"` Metrics }
Chat Response
type ToolCall ¶
type ToolCall struct {
Function ToolCallFunction `json:"function"`
}
type ToolCallFunction ¶
type ToolFunction ¶
type ToolFunction struct { Type string `json:"type"` // function Function llm.Tool `json:"function"` }
ToolFunction