Documentation
¶
Index ¶
- Constants
- Variables
- func Bool(v bool) *bool
- func Int(v int) *int
- type APIError
- type ChatNewParams
- type ChatResponse
- type ChatService
- type Client
- type EmbedResponse
- type EmbeddingNewParams
- type EmbeddingService
- type FunctionCall
- type GenerateNewParams
- type GenerateResponse
- type GenerateService
- type ListModelsResponse
- type ListRunningModelsResponse
- type LogProb
- type Message
- type Metrics
- type MissingFieldError
- type Model
- type ModelCopyParams
- type ModelCreateParams
- type ModelDeleteParams
- type ModelDetails
- type ModelPullParams
- type ModelPushParams
- type ModelService
- func (s *ModelService) Copy(ctx context.Context, params ModelCopyParams) error
- func (s *ModelService) Create(ctx context.Context, params ModelCreateParams) (*StatusResponse, error)
- func (s *ModelService) CreateStreaming(ctx context.Context, params ModelCreateParams, fn func(StatusResponse) error) error
- func (s *ModelService) Delete(ctx context.Context, params ModelDeleteParams) error
- func (s *ModelService) List(ctx context.Context) (*ListModelsResponse, error)
- func (s *ModelService) ListRunning(ctx context.Context) (*ListRunningModelsResponse, error)
- func (s *ModelService) Pull(ctx context.Context, params ModelPullParams) (*StatusResponse, error)
- func (s *ModelService) PullStreaming(ctx context.Context, params ModelPullParams, fn func(StatusResponse) error) error
- func (s *ModelService) Push(ctx context.Context, params ModelPushParams) (*StatusResponse, error)
- func (s *ModelService) PushStreaming(ctx context.Context, params ModelPushParams, fn func(StatusResponse) error) error
- func (s *ModelService) Show(ctx context.Context, params ModelShowParams) (*ShowResponse, error)
- type ModelShowParams
- type Option
- type OptionKey
- type Options
- type ShowResponse
- type StatusResponse
- type Tool
- type ToolCall
- type ToolFunction
- type TopLogProb
- type VersionResponse
- type VersionService
Constants ¶
const ( // DefaultBaseURL is the local Ollama API URL documented by Ollama. DefaultBaseURL = "http://localhost:11434/api" // CloudBaseURL is the hosted Ollama API URL used with API-key auth. CloudBaseURL = "https://ollama.com/api" )
const ( RoleSystem = "system" RoleUser = "user" RoleAssistant = "assistant" RoleTool = "tool" )
Variables ¶
var ( // ErrContextLengthExceeded indicates that an input or prompt does not fit // within the model's available context window. ErrContextLengthExceeded = errors.New("ollama: context length exceeded") // ErrModelNotFound indicates that the requested model is not available. ErrModelNotFound = errors.New("ollama: model not found") ErrUnauthorized = errors.New("ollama: unauthorized") // ErrRateLimited indicates that the server or an upstream service applied a // request rate limit. ErrRateLimited = errors.New("ollama: rate limited") // ErrServerBusy indicates that Ollama cannot currently schedule the request. ErrServerBusy = errors.New("ollama: server busy") // ErrUnsupportedCapability indicates that the selected model does not // support a capability required by the request. ErrUnsupportedCapability = errors.New("ollama: unsupported capability") )
Functions ¶
Types ¶
type ChatNewParams ¶
type ChatNewParams struct {
Model string `json:"model"`
Messages []Message `json:"messages"`
Tools []Tool `json:"tools,omitempty"`
Format any `json:"format,omitempty"`
Options Options `json:"options,omitempty"`
Stream *bool `json:"stream,omitempty"`
Think any `json:"think,omitempty"`
KeepAlive any `json:"keep_alive,omitempty"`
Truncate *bool `json:"truncate,omitempty"`
Shift *bool `json:"shift,omitempty"`
LogProbs *bool `json:"logprobs,omitempty"`
TopLogProbs *int `json:"top_logprobs,omitempty"`
}
ChatNewParams contains params for POST /api/chat.
type ChatResponse ¶
type ChatResponse struct {
Model string `json:"model"`
RemoteModel string `json:"remote_model,omitempty"`
RemoteHost string `json:"remote_host,omitempty"`
CreatedAt time.Time `json:"created_at"`
Message Message `json:"message"`
Done bool `json:"done"`
DoneReason string `json:"done_reason,omitempty"`
Metrics
LogProbs []LogProb `json:"logprobs,omitempty"`
}
ChatResponse is returned by /api/chat.
type ChatService ¶
type ChatService struct {
// contains filtered or unexported fields
}
ChatService handles /api/chat.
func (*ChatService) New ¶
func (s *ChatService) New(ctx context.Context, params ChatNewParams) (*ChatResponse, error)
New creates a non-streaming chat request.
func (*ChatService) NewStreaming ¶
func (s *ChatService) NewStreaming(ctx context.Context, params ChatNewParams, fn func(ChatResponse) error) error
NewStreaming creates a streaming chat request and calls fn for each chunk.
type Client ¶
type Client struct {
Generate *GenerateService
Chat *ChatService
Embeddings *EmbeddingService
Models *ModelService
Version *VersionService
// contains filtered or unexported fields
}
Client is an Ollama API client.
type EmbedResponse ¶
type EmbedResponse struct {
Model string `json:"model"`
Embeddings [][]float64 `json:"embeddings"`
TotalDuration int64 `json:"total_duration,omitempty"`
LoadDuration int64 `json:"load_duration,omitempty"`
PromptEvalCount int `json:"prompt_eval_count,omitempty"`
}
EmbedResponse is returned by /api/embed.
type EmbeddingNewParams ¶
type EmbeddingNewParams struct {
Model string `json:"model"`
Input any `json:"input"`
KeepAlive any `json:"keep_alive,omitempty"`
Truncate *bool `json:"truncate,omitempty"`
Dimensions *int `json:"dimensions,omitempty"`
Options Options `json:"options,omitempty"`
}
EmbeddingNewParams contains params for POST /api/embed.
type EmbeddingService ¶
type EmbeddingService struct {
// contains filtered or unexported fields
}
EmbeddingService handles /api/embed.
func (*EmbeddingService) New ¶
func (s *EmbeddingService) New(ctx context.Context, params EmbeddingNewParams) (*EmbedResponse, error)
New creates an embedding request.
type FunctionCall ¶
type FunctionCall struct {
Index int `json:"index,omitempty"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Arguments map[string]any `json:"arguments,omitempty"`
}
FunctionCall contains function call details returned by the model.
type GenerateNewParams ¶
type GenerateNewParams struct {
Model string `json:"model"`
Prompt string `json:"prompt,omitempty"`
Suffix string `json:"suffix,omitempty"`
Images []string `json:"images,omitempty"`
Format any `json:"format,omitempty"`
System string `json:"system,omitempty"`
Template string `json:"template,omitempty"`
Context []int `json:"context,omitempty"`
Stream *bool `json:"stream,omitempty"`
Think any `json:"think,omitempty"`
Raw *bool `json:"raw,omitempty"`
KeepAlive any `json:"keep_alive,omitempty"`
Options Options `json:"options,omitempty"`
Truncate *bool `json:"truncate,omitempty"`
Shift *bool `json:"shift,omitempty"`
LogProbs *bool `json:"logprobs,omitempty"`
TopLogProbs *int `json:"top_logprobs,omitempty"`
Width *int `json:"width,omitempty"`
Height *int `json:"height,omitempty"`
Steps *int `json:"steps,omitempty"`
}
GenerateNewParams contains params for POST /api/generate.
type GenerateResponse ¶
type GenerateResponse struct {
Model string `json:"model"`
RemoteModel string `json:"remote_model,omitempty"`
RemoteHost string `json:"remote_host,omitempty"`
CreatedAt time.Time `json:"created_at"`
Response string `json:"response"`
Thinking string `json:"thinking,omitempty"`
Done bool `json:"done"`
DoneReason string `json:"done_reason,omitempty"`
Metrics
Context []int `json:"context,omitempty"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
LogProbs []LogProb `json:"logprobs,omitempty"`
Image string `json:"image,omitempty"`
Completed int64 `json:"completed,omitempty"`
Total int64 `json:"total,omitempty"`
}
GenerateResponse is returned by /api/generate.
type GenerateService ¶
type GenerateService struct {
// contains filtered or unexported fields
}
GenerateService handles /api/generate.
func (*GenerateService) New ¶
func (s *GenerateService) New(ctx context.Context, params GenerateNewParams) (*GenerateResponse, error)
New creates a non-streaming generate request.
func (*GenerateService) NewStreaming ¶
func (s *GenerateService) NewStreaming(ctx context.Context, params GenerateNewParams, fn func(GenerateResponse) error) error
NewStreaming creates a streaming generate request and calls fn for each chunk.
type ListModelsResponse ¶
type ListModelsResponse struct {
Models []Model `json:"models"`
}
ListModelsResponse is returned by /api/tags.
type ListRunningModelsResponse ¶
type ListRunningModelsResponse struct {
Models []Model `json:"models"`
}
ListRunningModelsResponse is returned by /api/ps.
type LogProb ¶
type LogProb struct {
Token string `json:"token"`
LogProb float64 `json:"logprob"`
Bytes []int `json:"bytes,omitempty"`
TopLogProbs []TopLogProb `json:"top_logprobs,omitempty"`
}
LogProb contains log probability information for an output token.
type Message ¶
type Message struct {
Role string `json:"role"`
Content string `json:"content,omitempty"`
Thinking string `json:"thinking,omitempty"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
Images []string `json:"images,omitempty"`
ToolName string `json:"tool_name,omitempty"`
ToolCallID string `json:"tool_call_id,omitempty"`
}
Message is a chat message accepted and returned by /api/chat.
type Metrics ¶
type Metrics struct {
TotalDuration int64 `json:"total_duration,omitempty"`
LoadDuration int64 `json:"load_duration,omitempty"`
PromptEvalCount int `json:"prompt_eval_count,omitempty"`
PromptEvalDuration int64 `json:"prompt_eval_duration,omitempty"`
EvalCount int `json:"eval_count,omitempty"`
EvalDuration int64 `json:"eval_duration,omitempty"`
}
Metrics contains timing and token usage fields returned by generation endpoints.
type MissingFieldError ¶
type MissingFieldError struct {
Field string
}
MissingFieldError is returned before a request when a required builder field is empty.
func (*MissingFieldError) Error ¶
func (e *MissingFieldError) Error() string
type Model ¶
type Model struct {
Name string `json:"name"`
Model string `json:"model"`
ModifiedAt time.Time `json:"modified_at,omitempty"`
Size int64 `json:"size,omitempty"`
Digest string `json:"digest,omitempty"`
Details ModelDetails `json:"details,omitempty"`
ExpiresAt time.Time `json:"expires_at,omitempty"`
SizeVRAM int64 `json:"size_vram,omitempty"`
ContextLength int `json:"context_length,omitempty"`
}
Model contains local or running model metadata.
type ModelCopyParams ¶
type ModelCopyParams struct {
Source string `json:"source"`
Destination string `json:"destination"`
}
ModelCopyParams contains params for POST /api/copy.
type ModelCreateParams ¶
type ModelCreateParams struct {
Model string `json:"model"`
From string `json:"from,omitempty"`
RemoteHost string `json:"remote_host,omitempty"`
Files map[string]string `json:"files,omitempty"`
DraftFiles map[string]string `json:"draft_files,omitempty"`
Adapters map[string]string `json:"adapters,omitempty"`
Template string `json:"template,omitempty"`
License any `json:"license,omitempty"`
System string `json:"system,omitempty"`
Parameters map[string]any `json:"parameters,omitempty"`
Messages []Message `json:"messages,omitempty"`
Renderer string `json:"renderer,omitempty"`
Parser string `json:"parser,omitempty"`
Requires string `json:"requires,omitempty"`
Info map[string]any `json:"info,omitempty"`
Quantize string `json:"quantize,omitempty"`
DraftQuantize string `json:"draft_quantize,omitempty"`
Stream *bool `json:"stream,omitempty"`
}
ModelCreateParams contains params for POST /api/create.
type ModelDeleteParams ¶
type ModelDeleteParams struct {
Model string `json:"model"`
}
ModelDeleteParams contains params for DELETE /api/delete.
type ModelDetails ¶
type ModelDetails struct {
ParentModel string `json:"parent_model,omitempty"`
Format string `json:"format,omitempty"`
Family string `json:"family,omitempty"`
Families []string `json:"families,omitempty"`
ParameterSize string `json:"parameter_size,omitempty"`
QuantizationLevel string `json:"quantization_level,omitempty"`
}
ModelDetails contains high-level model metadata.
type ModelPullParams ¶
type ModelPullParams struct {
Model string `json:"model"`
Insecure *bool `json:"insecure,omitempty"`
Stream *bool `json:"stream,omitempty"`
}
ModelPullParams contains params for POST /api/pull.
type ModelPushParams ¶
type ModelPushParams struct {
Model string `json:"model"`
Insecure *bool `json:"insecure,omitempty"`
Stream *bool `json:"stream,omitempty"`
}
ModelPushParams contains params for POST /api/push.
type ModelService ¶
type ModelService struct {
// contains filtered or unexported fields
}
ModelService handles Ollama model endpoints.
func (*ModelService) Copy ¶
func (s *ModelService) Copy(ctx context.Context, params ModelCopyParams) error
Copy calls POST /api/copy.
func (*ModelService) Create ¶
func (s *ModelService) Create(ctx context.Context, params ModelCreateParams) (*StatusResponse, error)
Create calls POST /api/create.
func (*ModelService) CreateStreaming ¶
func (s *ModelService) CreateStreaming(ctx context.Context, params ModelCreateParams, fn func(StatusResponse) error) error
CreateStreaming calls POST /api/create with stream enabled.
func (*ModelService) Delete ¶
func (s *ModelService) Delete(ctx context.Context, params ModelDeleteParams) error
Delete calls DELETE /api/delete.
func (*ModelService) List ¶
func (s *ModelService) List(ctx context.Context) (*ListModelsResponse, error)
List calls GET /api/tags.
func (*ModelService) ListRunning ¶
func (s *ModelService) ListRunning(ctx context.Context) (*ListRunningModelsResponse, error)
ListRunning calls GET /api/ps.
func (*ModelService) Pull ¶
func (s *ModelService) Pull(ctx context.Context, params ModelPullParams) (*StatusResponse, error)
Pull calls POST /api/pull.
func (*ModelService) PullStreaming ¶
func (s *ModelService) PullStreaming(ctx context.Context, params ModelPullParams, fn func(StatusResponse) error) error
PullStreaming calls POST /api/pull with stream enabled.
func (*ModelService) Push ¶
func (s *ModelService) Push(ctx context.Context, params ModelPushParams) (*StatusResponse, error)
Push calls POST /api/push.
func (*ModelService) PushStreaming ¶
func (s *ModelService) PushStreaming(ctx context.Context, params ModelPushParams, fn func(StatusResponse) error) error
PushStreaming calls POST /api/push with stream enabled.
func (*ModelService) Show ¶
func (s *ModelService) Show(ctx context.Context, params ModelShowParams) (*ShowResponse, error)
Show calls POST /api/show.
type ModelShowParams ¶
type ModelShowParams struct {
Model string `json:"model"`
System string `json:"system,omitempty"`
Template string `json:"template,omitempty"`
Verbose *bool `json:"verbose,omitempty"`
Options map[string]any `json:"options,omitempty"`
}
ModelShowParams contains params for POST /api/show.
type Option ¶
Option configures a Client.
func WithBaseURL ¶
WithBaseURL sets the API base URL. If only a host is provided, /api is added.
func WithHTTPClient ¶
WithHTTPClient sets the HTTP client used for requests.
func WithHeader ¶
WithHeader sets a header on every request.
func WithHeaders ¶
WithHeaders sets multiple headers on every request.
func WithUserAgent ¶
WithUserAgent sets the User-Agent header sent with requests.
type OptionKey ¶
type OptionKey string
OptionKey is an enum-style key for Ollama runtime options.
const ( NumCtx OptionKey = "num_ctx" NumBatch OptionKey = "num_batch" NumGPU OptionKey = "num_gpu" MainGPU OptionKey = "main_gpu" UseMMap OptionKey = "use_mmap" NumThread OptionKey = "num_thread" DraftNumPredict OptionKey = "draft_num_predict" NumKeep OptionKey = "num_keep" Seed OptionKey = "seed" NumPredict OptionKey = "num_predict" TopK OptionKey = "top_k" TopP OptionKey = "top_p" MinP OptionKey = "min_p" TypicalP OptionKey = "typical_p" RepeatLastN OptionKey = "repeat_last_n" Temperature OptionKey = "temperature" RepeatPenalty OptionKey = "repeat_penalty" PresencePenalty OptionKey = "presence_penalty" FrequencyPenalty OptionKey = "frequency_penalty" Stop OptionKey = "stop" )
type ShowResponse ¶
type ShowResponse struct {
Parameters string `json:"parameters,omitempty"`
License any `json:"license,omitempty"`
ModifiedAt time.Time `json:"modified_at,omitempty"`
Details ModelDetails `json:"details,omitempty"`
Template string `json:"template,omitempty"`
Capabilities []string `json:"capabilities,omitempty"`
ModelInfo map[string]any `json:"model_info,omitempty"`
}
ShowResponse is returned by /api/show.
type StatusResponse ¶
type StatusResponse struct {
Status string `json:"status"`
Digest string `json:"digest,omitempty"`
Total int64 `json:"total,omitempty"`
Completed int64 `json:"completed,omitempty"`
}
StatusResponse is returned by model management endpoints that report progress.
type Tool ¶
type Tool struct {
Type string `json:"type,omitempty"`
Items any `json:"items,omitempty"`
Function ToolFunction `json:"function"`
}
Tool describes a callable function tool for chat requests.
type ToolCall ¶
type ToolCall struct {
ID string `json:"id,omitempty"`
Function FunctionCall `json:"function"`
}
ToolCall is a function call requested by the model.
type ToolFunction ¶
type ToolFunction struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Parameters any `json:"parameters,omitempty"`
}
ToolFunction describes a function exposed to the model.
type TopLogProb ¶
type TopLogProb struct {
Token string `json:"token"`
LogProb float64 `json:"logprob"`
Bytes []int `json:"bytes,omitempty"`
}
TopLogProb is an alternate token probability.
type VersionResponse ¶
type VersionResponse struct {
Version string `json:"version"`
}
VersionResponse is returned by /api/version.
type VersionService ¶
type VersionService struct {
// contains filtered or unexported fields
}
VersionService handles /api/version.
func (*VersionService) Get ¶
func (s *VersionService) Get(ctx context.Context) (*VersionResponse, error)
Get calls GET /api/version.