Skip to content

package ollama

import "kaiju/ollama"

Functions

ReflectFuncToOllama

func ReflectFuncToOllama(fn any, name, description string, argDescPair ...string) error

Stdin

func Stdin(hostAddr string, req APIRequest, reader func(think, msg string) error) error

Stream

func Stream(hostAddr string, request APIRequest, reader func(think, msg string) error) error

UnloadModel

func UnloadModel(hostAddr, modelName string) error

Types

APIRequest

struct

type APIRequest struct {
    Model      string               `json:"model"`
    Prompt     string               `json:"prompt"`
    Messages   []Message            `json:"messages"`
    Stream     bool                 `json:"stream"`
    Suffix     string               `json:"suffix,omitempty"`
    Images     []Base64EncodedImage `json:"images,omitempty"`
    Format     string               `json:"format,omitempty"`
    Template   string               `json:"template,omitempty"`
    KeepAlive  int                  `json:"keep_alive,omitempty"`
    System     string               `json:"system,omitempty"`
    Options    APIRequestOptions    `json:"options,omitempty"`
    Think      bool                 `json:"think,omitempty"`
    Raw        bool                 `json:"raw,omitempty"`
    Tools      []Tool               `json:"tools,omitempty"`
    RetryCount int
}

APIRequestOptions

struct

type APIRequestOptions struct {
    Mirostat      int     `json:"mirostat,omitempty"`
    MirostatEta   float64 `json:"mirostat_eta,omitempty"`
    MirostatTau   float64 `json:"mirostat_tau,omitempty"`
    NumCtx        int64   `json:"num_ctx,omitempty"`
    RepeatLastN   int     `json:"repeat_last_n,omitempty"`
    RepeatPenalty float64 `json:"repeat_penalty,omitempty"`
    Temperature   float64 `json:"temperature,omitempty"`
    Seed          int     `json:"seed,omitempty"`
    Stop          string  `json:"stop,omitempty"`
    NumPredict    int     `json:"num_predict,omitempty"`
    TopK          int     `json:"top_k,omitempty"`
    TopP          float64 `json:"top_p,omitempty"`
    MinP          float64 `json:"min_p,omitempty"`
}

APIResponse

struct

type APIResponse struct {
    Model              string    `json:"model"`
    Created            time.Time `json:"created_at"`
    Thinking           string    `json:"thinking"`
    Response           string    `json:"response"`
    Message            Message   `json:"message"`
    Done               bool      `json:"done"`
    TotalDuration      int64     `json:"total_duration"`
    LoadDuration       int64     `json:"load_duration"`
    PromptEvalCount    int64     `json:"prompt_eval_count"`
    PromptEvalDuration int64     `json:"prompt_eval_duration"`
    EvalCount          int64     `json:"eval_count"`
    EvalDuration       int64     `json:"eval_duration"`
    Error              string    `json:"error"`
}

Chat

func Chat(hostAddr string, req APIRequest) (APIResponse, error)

Base64EncodedImage

string

type Base64EncodedImage = string

Function

struct

type Function struct {
    Name        string             `json:"name"`
    Description string             `json:"description"`
    Parameters  FunctionParameters `json:"parameters"`
}

FunctionParameterProperty

struct

type FunctionParameterProperty struct {
    Type        string   `json:"type"`
    Description string   `json:"description"`
    Enum        []string `json:"enum,omitempty"`
}

FunctionParameters

struct

type FunctionParameters struct {
    Type       string                               `json:"type"`
    Properties map[string]FunctionParameterProperty `json:"properties"`
    Required   []string                             `json:"required,omitempty"`
}

Message

struct

type Message struct {
    Role               string     `json:"role"`
    Content            string     `json:"content"`
    ToolCalls          []ToolCall `json:"tool_calls"`
    DoneReason         string     `json:"done_reason"`
    Done               bool       `json:"done"`
    TotalDuration      uint64     `json:"total_duration"`
    LoadDuration       uint64     `json:"load_duration"`
    PromptEvalCount    uint64     `json:"prompt_eval_count"`
    PromptEvalDuration uint64     `json:"prompt_eval_duration"`
    EvalCount          uint64     `json:"eval_count"`
    EvalDuration       uint64     `json:"eval_duration"`
}

Tool

struct

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

ToolCall

struct

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

ToolCallFunction

struct

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

ToolFunc

struct

type ToolFunc struct {
    // Has unexported fields.
}