Documentation
¶
Index ¶
- Constants
- type ChatRequest
- type ChatResponse
- type DeleteRequest
- type FunctionCall
- type GenerateRequest
- type GenerateResponse
- type HTTPHandler
- type ListResponse
- type Message
- type ModelDetails
- type ModelResponse
- type PSModel
- type PullRequest
- type ShowRequest
- type ShowResponse
- type Tool
- type ToolCall
- type ToolFunction
Constants ¶
const (
// APIPrefix Ollama API prefix
APIPrefix = "/api"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChatRequest ¶
type ChatRequest struct {
Name string `json:"name"` // Ollama uses 'name' field
Model string `json:"model"` // Also accept 'model' for compatibility
Messages []Message `json:"messages"`
Tools []Tool `json:"tools,omitempty"` // Function calling tools
Stream *bool `json:"stream,omitempty"`
Think interface{} `json:"think,omitempty"` // Can be bool or string ("high", "medium", "low") for reasoning/thinking models
KeepAlive string `json:"keep_alive,omitempty"` // Duration like "5m" or "0s" to unload immediately
Options map[string]interface{} `json:"options,omitempty"`
}
ChatRequest is the request for /api/chat
type ChatResponse ¶
type ChatResponse struct {
Model string `json:"model"`
CreatedAt time.Time `json:"created_at"`
Message Message `json:"message,omitempty"`
Done bool `json:"done"`
DoneReason string `json:"done_reason,omitempty"`
}
ChatResponse is the response for /api/chat
type DeleteRequest ¶
type DeleteRequest struct {
Name string `json:"name"` // Ollama uses 'name' field
Model string `json:"model"` // Also accept 'model' for compatibility
}
DeleteRequest is the request for DELETE /api/delete
type FunctionCall ¶ added in v1.0.7
type FunctionCall struct {
Index *int `json:"index,omitempty"`
Name string `json:"name"`
Arguments interface{} `json:"arguments"` // Can be JSON string (request) or object (response)
}
FunctionCall represents the details of a function call
type GenerateRequest ¶
type GenerateRequest struct {
Name string `json:"name"` // Ollama uses 'name' field
Model string `json:"model"` // Also accept 'model' for compatibility
Prompt string `json:"prompt"`
Stream *bool `json:"stream,omitempty"`
Think interface{} `json:"think,omitempty"` // Can be bool or string ("high", "medium", "low") for reasoning/thinking models
KeepAlive string `json:"keep_alive,omitempty"` // Duration like "5m" or "0s" to unload immediately
Options map[string]interface{} `json:"options,omitempty"`
}
GenerateRequest is the request for /api/generate
type GenerateResponse ¶
type GenerateResponse struct {
Model string `json:"model"`
CreatedAt time.Time `json:"created_at"`
Response string `json:"response,omitempty"`
Thinking string `json:"thinking,omitempty"` // The model's generated thinking output
Done bool `json:"done"`
}
GenerateResponse is the response for /api/generate
type HTTPHandler ¶ added in v1.0.7
type HTTPHandler struct {
// contains filtered or unexported fields
}
HTTPHandler implements the Ollama API compatibility layer
func NewHTTPHandler ¶ added in v1.0.7
func NewHTTPHandler(log logging.Logger, scheduler *scheduling.Scheduler, schedulerHTTP http.Handler, allowedOrigins []string, modelManager *models.Manager) *HTTPHandler
NewHTTPHandler creates a new Ollama API handler
func (*HTTPHandler) ServeHTTP ¶ added in v1.0.7
func (h *HTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements the http.Handler interface
type ListResponse ¶
type ListResponse struct {
Models []ModelResponse `json:"models"`
}
ListResponse is the response for /api/tags
type Message ¶
type Message struct {
Role string `json:"role"`
Content string `json:"content"`
Images []string `json:"images,omitempty"` // For multimodal support
ToolCalls []ToolCall `json:"tool_calls,omitempty"` // For function calling
ToolCallID string `json:"tool_call_id,omitempty"` // For tool results
Thinking string `json:"thinking,omitempty"` // Internal field for model's thinking output
}
Message represents a chat message
type ModelDetails ¶
type ModelDetails struct {
Format string `json:"format"`
Family string `json:"family"`
Families []string `json:"families"`
ParameterSize string `json:"parameter_size"`
QuantizationLevel string `json:"quantization_level"`
}
ModelDetails contains model metadata
type ModelResponse ¶
type ModelResponse struct {
Name string `json:"name"`
Model string `json:"model"`
ModifiedAt time.Time `json:"modified_at"`
Size int64 `json:"size"`
Digest string `json:"digest"`
Details ModelDetails `json:"details"`
}
ModelResponse represents a single model in the list
type PSModel ¶
type PSModel struct {
Name string `json:"name"`
Model string `json:"model"`
Size int64 `json:"size"`
Digest string `json:"digest"`
ExpiresAt time.Time `json:"expires_at,omitempty"`
SizeVram int64 `json:"size_vram,omitempty"`
}
PSModel represents a running model in the ps response
type PullRequest ¶
type PullRequest struct {
Name string `json:"name"` // Ollama uses 'name' field
Model string `json:"model"` // Also accept 'model' for compatibility
Insecure bool `json:"insecure,omitempty"`
Stream *bool `json:"stream,omitempty"`
}
PullRequest is the request for POST /api/pull
type ShowRequest ¶
type ShowRequest struct {
Name string `json:"name"` // Ollama uses 'name' field
Model string `json:"model"` // Also accept 'model' for compatibility
Verbose bool `json:"verbose,omitempty"`
}
ShowRequest is the request for /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"`
Details ModelDetails `json:"details,omitempty"`
}
ShowResponse is the response for /api/show
type Tool ¶ added in v1.0.7
type Tool struct {
Type string `json:"type"` // Always "function" for now
Function ToolFunction `json:"function"`
}
Tool represents a tool/function definition
type ToolCall ¶ added in v1.0.7
type ToolCall struct {
ID string `json:"id"`
Type string `json:"type,omitempty"` // Always "function" for now
Function FunctionCall `json:"function"`
}
ToolCall represents a function call made by the model
type ToolFunction ¶ added in v1.0.7
type ToolFunction struct {
Name string `json:"name"`
Description string `json:"description"`
Parameters map[string]interface{} `json:"parameters"` // JSON Schema
}
ToolFunction represents a function definition