runtime

package
v0.1.27 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 12 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsKind

func IsKind(err error, kind ErrorKind) bool

func NewError

func NewError(engine Engine, kind ErrorKind, status int, msg string, err error) error

Types

type ChatRequest

type ChatRequest struct {
	Model       string    `json:"model,omitempty"`
	Messages    []Message `json:"messages"`
	Tools       []Tool    `json:"tools,omitempty"`
	Temperature *float64  `json:"temperature,omitempty"`
	MaxTokens   int       `json:"max_tokens,omitempty"`
	// ContextLength is an optional context-window hint in tokens. Runtimes
	// that manage their own context (OpenAI-compatible servers) ignore it;
	// the Ollama runtime maps it to num_ctx.
	ContextLength int               `json:"context_length,omitempty"`
	Metadata      map[string]string `json:"metadata,omitempty"`
}

type ChatResponse

type ChatResponse struct {
	Model      string  `json:"model"`
	Message    Message `json:"message"`
	Usage      Usage   `json:"usage"`
	RawContent string  `json:"raw_content,omitempty"`
}

type Config

type Config struct {
	Engine    Engine            `json:"engine" yaml:"engine"`
	BaseURL   string            `json:"base_url" yaml:"base_url"`
	APIKey    string            `json:"api_key,omitempty" yaml:"api_key,omitempty"`
	Model     string            `json:"model,omitempty" yaml:"model,omitempty"`
	Headers   map[string]string `json:"headers,omitempty" yaml:"headers,omitempty"`
	TimeoutMS int               `json:"timeout_ms,omitempty" yaml:"timeout_ms,omitempty"`
}

func (Config) Timeout

func (c Config) Timeout() time.Duration

type Engine

type Engine string
const (
	EngineOllama Engine = "ollama"
	EngineSGLang Engine = "sglang"
	EngineVLLM   Engine = "vllm"
)

type Error

type Error struct {
	Kind       ErrorKind
	Engine     Engine
	StatusCode int
	Message    string
	Err        error
}

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type ErrorKind

type ErrorKind string
const (
	ErrorKindInvalidRequest ErrorKind = "invalid_request"
	ErrorKindUnauthorized   ErrorKind = "unauthorized"
	ErrorKindRateLimited    ErrorKind = "rate_limited"
	ErrorKindUnavailable    ErrorKind = "unavailable"
	ErrorKindTimeout        ErrorKind = "timeout"
	ErrorKindProvider       ErrorKind = "provider"
	ErrorKindParse          ErrorKind = "parse"
)

func Kind

func Kind(err error) (ErrorKind, bool)

func KindFromStatus

func KindFromStatus(status int) ErrorKind

type HealthStatus

type HealthStatus struct {
	Healthy bool   `json:"healthy"`
	Engine  Engine `json:"engine,omitempty"`
	Detail  string `json:"detail,omitempty"`
}

type Message

type Message struct {
	Role             string `json:"role"`
	Content          string `json:"content,omitempty"`
	ReasoningContent string `json:"reasoning_content,omitempty"`
	// ToolCallID correlates a role:"tool" message with the assistant tool call
	// it answers (OpenAI-compatible servers).
	ToolCallID string `json:"tool_call_id,omitempty"`
	// ToolName is the function name for a role:"tool" message. Runtimes that
	// key tool results by name (Ollama) use this instead of ToolCallID.
	ToolName  string     `json:"-"`
	ToolCalls []ToolCall `json:"tool_calls,omitempty"`
}

type ModelRuntime

type ModelRuntime interface {
	Engine() Engine
	Health(context.Context) (*HealthStatus, error)
	Chat(context.Context, ChatRequest) (*ChatResponse, error)
	Stream(context.Context, ChatRequest) (<-chan StreamEvent, error)
	GenerateStructured(context.Context, StructuredRequest) (*StructuredResponse, error)
}

type OpenAICompatibleRuntime

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

func NewOpenAICompatibleRuntime

func NewOpenAICompatibleRuntime(cfg Config) (*OpenAICompatibleRuntime, error)

func (*OpenAICompatibleRuntime) Chat

func (*OpenAICompatibleRuntime) Engine

func (r *OpenAICompatibleRuntime) Engine() Engine

func (*OpenAICompatibleRuntime) GenerateStructured

func (*OpenAICompatibleRuntime) Health

func (*OpenAICompatibleRuntime) Stream

func (r *OpenAICompatibleRuntime) Stream(ctx context.Context, req ChatRequest) (<-chan StreamEvent, error)

type RuntimeConfig

type RuntimeConfig struct {
	Primary  Config  `json:"primary" yaml:"primary"`
	Fallback *Config `json:"fallback,omitempty" yaml:"fallback,omitempty"`
}

type StreamEvent

type StreamEvent struct {
	Kind  StreamEventKind
	Delta string
	Err   error
}

type StreamEventKind

type StreamEventKind string
const (
	StreamEventDelta StreamEventKind = "delta"
	StreamEventDone  StreamEventKind = "done"
	StreamEventError StreamEventKind = "error"
)

type StructuredRequest

type StructuredRequest struct {
	ChatRequest
	Name   string
	Strict bool
	Schema map[string]any
}

type StructuredResponse

type StructuredResponse struct {
	Content string
	Parsed  any
}

type Tool

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

type ToolCall

type ToolCall struct {
	ID       string           `json:"id,omitempty"`
	Type     string           `json:"type,omitempty"`
	Function ToolCallFunction `json:"function"`
}

type ToolCallFunction

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

func (ToolCallFunction) MarshalJSON

func (f ToolCallFunction) MarshalJSON() ([]byte, error)

func (*ToolCallFunction) UnmarshalJSON

func (f *ToolCallFunction) UnmarshalJSON(data []byte) error

type ToolFunction

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

type Usage

type Usage struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

Jump to

Keyboard shortcuts

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