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() llm.Opt
- type Client
- 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) LoadModel(ctx context.Context, name string) (llm.Model, error)
- func (ollama *Client) Model(ctx context.Context, name string) llm.Model
- 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)
- func (ollama *Client) UnloadModel(ctx context.Context, name string) error
- type EmbeddingMeta
- type ImageData
- type Message
- type Metrics
- type ModelDetails
- type ModelInfo
- type ModelMeta
- type PullStatus
- type Response
- type RoleContent
- type ToolCall
- type ToolCallFunction
- type ToolCalls
- type ToolResults
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 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
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"`
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
type RoleContent ¶ added in v0.0.3
type ToolCall ¶
type ToolCall struct {
Type string `json:"type"` // function
Function ToolCallFunction `json:"function"`
}
type ToolCallFunction ¶
type ToolResults ¶ added in v0.0.6
type ToolResults struct {
Name string `json:"name,omitempty"` // function name - when role is tool
}