Documentation
¶
Overview ¶
Package libollama provides byte-exact wire types and serialization routines for the Ollama HTTP API specification.
Index ¶
- Constants
- type Capability
- type ChatRequest
- type ChatResponse
- type Duration
- type EmbedRequest
- type EmbedResponse
- type GenerateRequest
- type GenerateResponse
- type ImageData
- type ListModelResponse
- type ListResponse
- type Logprob
- type Message
- type Metrics
- type ModelDetails
- type PropertyType
- type ShowRequest
- type ShowResponse
- type ThinkValue
- type TokenLogprob
- type Tool
- type ToolCall
- type ToolCallFunction
- type ToolCallFunctionArguments
- type ToolFunction
- type ToolFunctionParameters
- type ToolPropertiesMap
- type ToolProperty
- type Tools
Constants ¶
const ( CapabilityCompletion = Capability("completion") CapabilityTools = Capability("tools") CapabilityVision = Capability("vision") CapabilityEmbedding = Capability("embedding") CapabilityThinking = Capability("thinking") )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChatRequest ¶
type ChatRequest struct {
Model string `json:"model"`
Messages []Message `json:"messages"`
Stream *bool `json:"stream,omitempty"`
Format json.RawMessage `json:"format,omitempty"`
KeepAlive *Duration `json:"keep_alive,omitempty"`
Tools `json:"tools,omitempty"`
Options map[string]any `json:"options,omitempty"`
Think *ThinkValue `json:"think,omitempty"`
Truncate *bool `json:"truncate,omitempty"`
Shift *bool `json:"shift,omitempty"`
DebugRenderOnly bool `json:"_debug_render_only,omitempty"`
Logprobs bool `json:"logprobs,omitempty"`
TopLogprobs int `json:"top_logprobs,omitempty"`
}
ChatRequest is the body of 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"`
Logprobs []Logprob `json:"logprobs,omitempty"`
Metrics
}
ChatResponse is one frame of POST /api/chat.
type Duration ¶
Duration is a time.Duration that marshals as an Ollama duration string ("10m0s") and unmarshals from either that or a number of seconds.
func (Duration) MarshalJSON ¶
MarshalJSON emits -1 for negative durations and a duration string otherwise.
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON accepts a number of seconds or a Go duration string.
type EmbedRequest ¶
type EmbedRequest struct {
Model string `json:"model"`
Input any `json:"input"`
KeepAlive *Duration `json:"keep_alive,omitempty"`
Truncate *bool `json:"truncate,omitempty"`
Dimensions int `json:"dimensions,omitempty"`
Options map[string]any `json:"options,omitempty"`
}
EmbedRequest is the body of POST /api/embed.
type EmbedResponse ¶
type EmbedResponse struct {
Model string `json:"model"`
Embeddings [][]float32 `json:"embeddings"`
TotalDuration time.Duration `json:"total_duration,omitempty"`
LoadDuration time.Duration `json:"load_duration,omitempty"`
PromptEvalCount int `json:"prompt_eval_count,omitempty"`
}
EmbedResponse is the response to POST /api/embed.
type GenerateRequest ¶
type GenerateRequest struct {
Model string `json:"model"`
Prompt string `json:"prompt"`
Suffix string `json:"suffix,omitempty"`
System string `json:"system,omitempty"`
Template string `json:"template,omitempty"`
Context []int `json:"context,omitempty"`
Stream *bool `json:"stream,omitempty"`
Raw bool `json:"raw,omitempty"`
Format json.RawMessage `json:"format,omitempty"`
KeepAlive *Duration `json:"keep_alive,omitempty"`
Images []ImageData `json:"images,omitempty"`
Options map[string]any `json:"options,omitempty"`
Think *ThinkValue `json:"think,omitempty"`
Truncate *bool `json:"truncate,omitempty"`
Shift *bool `json:"shift,omitempty"`
DebugRenderOnly bool `json:"_debug_render_only,omitempty"`
Logprobs bool `json:"logprobs,omitempty"`
TopLogprobs int `json:"top_logprobs,omitempty"`
}
GenerateRequest is the body of 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"`
Context []int `json:"context,omitempty"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
Logprobs []Logprob `json:"logprobs,omitempty"`
Metrics
}
GenerateResponse is one frame of POST /api/generate.
type ImageData ¶
type ImageData []byte
ImageData is the raw binary content of an image, rendered as base64 in JSON.
type ListModelResponse ¶
type ListModelResponse struct {
Name string `json:"name"`
Model string `json:"model"`
RemoteModel string `json:"remote_model,omitempty"`
RemoteHost string `json:"remote_host,omitempty"`
ModifiedAt time.Time `json:"modified_at"`
Size int64 `json:"size"`
Digest string `json:"digest"`
Details ModelDetails `json:"details,omitempty"`
}
ListModelResponse is one model in a ListResponse.
type ListResponse ¶
type ListResponse struct {
Models []ListModelResponse `json:"models"`
}
ListResponse is the response to GET /api/tags.
type Logprob ¶
type Logprob struct {
TokenLogprob
TopLogprobs []TokenLogprob `json:"top_logprobs,omitempty"`
}
Logprob is the log probability of a generated token plus its alternatives.
type Message ¶
type Message struct {
Role string `json:"role"`
Content string `json:"content"`
Thinking string `json:"thinking,omitempty"`
Images []ImageData `json:"images,omitempty"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
ToolName string `json:"tool_name,omitempty"`
ToolCallID string `json:"tool_call_id,omitempty"`
}
Message is one entry in a chat sequence.
func (*Message) UnmarshalJSON ¶
UnmarshalJSON lowercases Role for case-insensitive matching.
type Metrics ¶
type Metrics struct {
TotalDuration time.Duration `json:"total_duration,omitempty"`
PeakMemory uint64 `json:"peak_memory,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 are execution metrics in completion responses.
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 describes a model's format and provenance.
type PropertyType ¶
type PropertyType []string
PropertyType is a JSON Schema type as a single string or an array of strings.
func (PropertyType) MarshalJSON ¶
func (pt PropertyType) MarshalJSON() ([]byte, error)
MarshalJSON collapses single-item types to a bare string.
func (*PropertyType) UnmarshalJSON ¶
func (pt *PropertyType) UnmarshalJSON(data []byte) error
UnmarshalJSON parses a bare string or array of strings.
type ShowRequest ¶
type ShowRequest 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"`
}
ShowRequest is the body of POST /api/show.
type ShowResponse ¶
type ShowResponse struct {
License string `json:"license,omitempty"`
Modelfile string `json:"modelfile,omitempty"`
Parameters string `json:"parameters,omitempty"`
Template string `json:"template,omitempty"`
System string `json:"system,omitempty"`
Details ModelDetails `json:"details,omitempty"`
Messages []Message `json:"messages,omitempty"`
RemoteModel string `json:"remote_model,omitempty"`
RemoteHost string `json:"remote_host,omitempty"`
ModelInfo map[string]any `json:"model_info,omitempty"`
Capabilities []Capability `json:"capabilities,omitempty"`
ModifiedAt time.Time `json:"modified_at,omitempty"`
}
ShowResponse is the response to POST /api/show.
type ThinkValue ¶
type ThinkValue struct {
Value any
}
ThinkValue is the think request field: a bool, or one of "high", "medium", "low".
func (*ThinkValue) MarshalJSON ¶
func (t *ThinkValue) MarshalJSON() ([]byte, error)
MarshalJSON emits the underlying bool or string; a nil value emits null.
func (*ThinkValue) UnmarshalJSON ¶
func (t *ThinkValue) UnmarshalJSON(data []byte) error
UnmarshalJSON accepts a bool or one of "high", "medium", "low".
type TokenLogprob ¶
type TokenLogprob struct {
Token string `json:"token"`
Logprob float64 `json:"logprob"`
Bytes []int `json:"bytes,omitempty"`
}
TokenLogprob is the log probability of one token alternative.
type Tool ¶
type Tool struct {
Type string `json:"type"`
Items any `json:"items,omitempty"`
Function ToolFunction `json:"function"`
}
Tool is one tool offered to the model.
type ToolCall ¶
type ToolCall struct {
ID string `json:"id,omitempty"`
Function ToolCallFunction `json:"function"`
}
ToolCall is a single tool invocation requested by the model.
type ToolCallFunction ¶
type ToolCallFunction struct {
Index int `json:"index"`
Name string `json:"name"`
Arguments ToolCallFunctionArguments `json:"arguments"`
}
ToolCallFunction names the tool and carries its arguments.
type ToolCallFunctionArguments ¶
type ToolCallFunctionArguments struct {
// contains filtered or unexported fields
}
ToolCallFunctionArguments holds tool-call arguments in the order emitted.
func (ToolCallFunctionArguments) MarshalJSON ¶
func (t ToolCallFunctionArguments) MarshalJSON() ([]byte, error)
MarshalJSON encodes arguments preserving key order.
func (*ToolCallFunctionArguments) String ¶
func (t *ToolCallFunctionArguments) String() string
String renders the arguments as a JSON object string.
func (*ToolCallFunctionArguments) UnmarshalJSON ¶
func (t *ToolCallFunctionArguments) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes arguments preserving key order.
type ToolFunction ¶
type ToolFunction struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Parameters ToolFunctionParameters `json:"parameters"`
}
ToolFunction describes a callable tool.
type ToolFunctionParameters ¶
type ToolFunctionParameters struct {
Type string `json:"type"`
Defs any `json:"$defs,omitempty"`
Items any `json:"items,omitempty"`
Required []string `json:"required,omitempty"`
Properties *ToolPropertiesMap `json:"properties"`
}
ToolFunctionParameters describes a tool's JSON Schema parameters.
type ToolPropertiesMap ¶
type ToolPropertiesMap struct {
// contains filtered or unexported fields
}
ToolPropertiesMap holds schema properties in declaration order.
func (ToolPropertiesMap) MarshalJSON ¶
func (t ToolPropertiesMap) MarshalJSON() ([]byte, error)
MarshalJSON encodes properties preserving declaration order.
func (*ToolPropertiesMap) UnmarshalJSON ¶
func (t *ToolPropertiesMap) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes properties preserving declaration order.
type ToolProperty ¶
type ToolProperty struct {
AnyOf []ToolProperty `json:"anyOf,omitempty"`
Type PropertyType `json:"type,omitempty"`
Items any `json:"items,omitempty"`
Description string `json:"description,omitempty"`
Enum []any `json:"enum,omitempty"`
Properties *ToolPropertiesMap `json:"properties,omitempty"`
}
ToolProperty is one JSON Schema property of a tool's parameters.