ollama

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxScannerBuffer = 512 * 1000
	UserAgent        = "ollama/prometheus"
)
View Source
const ToolSystemPrompt = `` /* 163-byte string literal not displayed */

Variables

View Source
var Styles = map[string]RespondStyle{
	string(ConciseStyle): {
		Style:    ConciseStyle,
		Template: "Reply with shorter responses and keep the messages concise and to the point.",
	},
	string(DefaultStyle): {
		Style:    DefaultStyle,
		Template: "",
	},
	string(FormalStyle): {
		Style:    FormalStyle,
		Template: "Reply in a clear, well-structured and formal tone.",
	},
}

Functions

This section is empty.

Types

type ChatMessage

type ChatMessage struct {
	ToolCalls []ToolCall `json:"tool_calls,omitempty"`
	Role      string     `json:"role"`
	Content   string     `json:"content"`
}

type ChatRequest

type ChatRequest struct {
	Model       string        `json:"model"`
	Messages    []ChatMessage `json:"messages"`
	KeepAlive   int           `json:"keep_alive"`
	ContextSize int           `json:"context_size"`
}

type ChatResponse

type ChatResponse struct {
	Model      string      `json:"model"`
	CreatedAt  time.Time   `json:"created_at"`
	Message    ChatMessage `json:"message"`
	DoneReason string      `json:"done_reason,omitempty"`

	Done bool `json:"done"`
}

type ChatResponseHandler

type ChatResponseHandler func(ChatResponse) error

type Client

type Client struct {
	Endpoint string `json:"endpoint"`
	Model    string `json:"model,omitempty"`
	Style    Style  `json:"style,omitempty"`
	// contains filtered or unexported fields
}

func CreateClient

func CreateClient(endpoint, model string, http *http.Client) *Client

func (*Client) AddSystemPrompt

func (c *Client) AddSystemPrompt(req *ChatRequest, system string, data any) error

func (*Client) Chat

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

func (*Client) ChatTools

func (c *Client) ChatTools(ctx context.Context, req ChatRequest, resHandler ChatResponseHandler, toolHandler ToolCallHandler, tools []Tool) error

func (*Client) Embed

func (c *Client) Embed(ctx context.Context, req EmbedRequest) (*EmbedResponse, error)

func (*Client) EmbedHandle

func (c *Client) EmbedHandle(ctx context.Context, req EmbedRequest, handler EmbedResponseHandler) error

type EmbedRequest

type EmbedRequest struct {
	Model string `json:"model,omitempty"`
	Input any    `json:"input"`
}

type EmbedResponse

type EmbedResponse struct {
	Model      string      `json:"model"`
	Embeddings [][]float32 `json:"embeddings"`
}

type EmbedResponseHandler

type EmbedResponseHandler func(EmbedResponse) error

type RespondStyle

type RespondStyle struct {
	Style    Style  `json:"style"`
	Template string `json:"template"`
}

type Style

type Style string
const (
	ConciseStyle Style = "concise"
	DefaultStyle Style = "default"
	FormalStyle  Style = "formal"
)

type Tool

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

type ToolCall

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

type ToolCallFunction

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

type ToolCallHandler

type ToolCallHandler func(ToolCall) (string, error)

type ToolFunction

type ToolFunction struct {
	Name        string                `json:"name"`
	Description string                `json:"description"`
	Parameters  ToolFunctionParameter `json:"parameters"`
}

type ToolFunctionParameter

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

type ToolFunctionProperty

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

Jump to

Keyboard shortcuts

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