ollama

package
v0.1.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ollama provides a minimal Ollama REST client for Prism.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatRequest

type ChatRequest struct {
	Model    string    `json:"model"`
	Messages []Message `json:"messages"`
	Tools    []Tool    `json:"tools,omitempty"`
	Stream   bool      `json:"stream"`
	// Format constrains the response to a JSON schema (Ollama structured
	// outputs). Pass a marshalled JSON schema object.
	Format  json.RawMessage `json:"format,omitempty"`
	Options *Options        `json:"options,omitempty"`
}

ChatRequest is the payload for POST /api/chat.

type ChatResponse

type ChatResponse struct {
	Model   string  `json:"model"`
	Message Message `json:"message"`
	Done    bool    `json:"done"`
	// Token counts (present when Ollama is configured to return them).
	PromptEvalCount int `json:"prompt_eval_count"`
	EvalCount       int `json:"eval_count"`
	// Total generation duration in nanoseconds.
	TotalDuration int64 `json:"total_duration"`
}

ChatResponse is the non-streaming response from POST /api/chat.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a lightweight Ollama REST client.

func NewClient

func NewClient(host string) *Client

NewClient creates a Client targeting host. If host is empty it defaults to http://127.0.0.1:11434.

func (*Client) Chat

func (c *Client) Chat(ctx context.Context, req ChatRequest) (*ChatResponse, error)

Chat sends a non-streaming chat request and returns the full response.

func (*Client) Host

func (c *Client) Host() string

Host returns the configured Ollama host URL.

func (*Client) ListModels

func (c *Client) ListModels(ctx context.Context) ([]string, error)

ListModels returns the model tags available on the local Ollama server.

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping checks that the Ollama server is reachable.

type Message

type Message struct {
	Role      string     `json:"role"` // system | user | assistant | tool
	Content   string     `json:"content"`
	ToolName  string     `json:"tool_name,omitempty"`
	ToolCalls []ToolCall `json:"tool_calls,omitempty"`
}

Message is one turn in an Ollama conversation.

type Options

type Options struct {
	// Temperature is a pointer so an explicit 0 (deterministic sampling) is
	// serialized instead of being dropped by omitempty.
	Temperature *float64 `json:"temperature,omitempty"`
	// NumCtx is the context window size in tokens passed to the model.
	NumCtx     int `json:"num_ctx,omitempty"`
	NumPredict int `json:"num_predict,omitempty"`
}

Options maps to Ollama model parameters.

type Tool added in v0.1.14

type Tool struct {
	Type     string       `json:"type"`
	Function ToolFunction `json:"function"`
}

type ToolCall added in v0.1.14

type ToolCall struct {
	Function ToolCallFunction `json:"function"`
}

type ToolCallFunction added in v0.1.14

type ToolCallFunction struct {
	Name      string         `json:"name"`
	Arguments map[string]any `json:"arguments,omitempty"`
}

type ToolFunction added in v0.1.14

type ToolFunction struct {
	Name        string         `json:"name"`
	Description string         `json:"description,omitempty"`
	Parameters  map[string]any `json:"parameters,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL