Help us shape the future of Go! Take the 2026 Go Developer Survey

model

package
v0.2.50 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const MaxRequestBytes = 1 << 20
View Source
const MaxRetryAfter = 6 * time.Hour
View Source
const MaxToolArguments = 256 << 10
View Source
const MaxTurnTimeout = 10 * time.Minute

Variables

This section is empty.

Functions

func RetryAfter added in v0.2.30

func RetryAfter(header http.Header, now time.Time) time.Duration

Types

type Capabilities

type Capabilities struct {
	Provider     string                       `json:"provider"`
	Model        string                       `json:"model"`
	Features     map[string]domain.Capability `json:"features"`
	BillingRoute string                       `json:"billing_route"`
}

type Config

type Config struct {
	Endpoint string
	APIKey   string `json:"-"`
	Model    string
	Client   HTTPClient `json:"-"`
	Profile  string
}

func (Config) GoString

func (c Config) GoString() string

func (Config) LogValue

func (c Config) LogValue() slog.Value

func (Config) String

func (c Config) String() string

type Event

type Event struct {
	Type         string          `json:"type"`
	ID           string          `json:"id"`
	Text         string          `json:"text,omitempty"`
	ToolCall     *ToolCall       `json:"tool_call,omitempty"`
	Usage        *Usage          `json:"usage,omitempty"`
	Continuation json.RawMessage `json:"-"`
	FinishReason string          `json:"finish_reason,omitempty"`
}

type HTTPClient

type HTTPClient interface {
	Do(*http.Request) (*http.Response, error)
}

type Message

type Message struct {
	Role       string          `json:"role"`
	Text       string          `json:"text"`
	ToolCalls  []ToolCall      `json:"tool_calls,omitempty"`
	ToolCallID string          `json:"tool_call_id,omitempty"`
	Opaque     json.RawMessage `json:"-"`
}

type Model

type Model struct {
	ID           string `json:"id"`
	Name         string `json:"name,omitempty"`
	ContextLimit int    `json:"context_limit"`
	OutputLimit  int    `json:"output_limit"`
}

type ModelLister

type ModelLister interface {
	ListModels(context.Context) ([]Model, error)
}

type ModelProvider

type ModelProvider interface {
	Probe(context.Context) (Capabilities, error)
	ListModels(context.Context) ([]Model, error)
	StreamTurn(context.Context, TurnRequest, func(Event) error) error
	EstimateUsage(TurnRequest) Usage
}

type Tool

type Tool struct {
	Name        string          `json:"name"`
	Description string          `json:"description"`
	Schema      json.RawMessage `json:"schema"`
}

type ToolCall

type ToolCall struct {
	ID        string          `json:"id"`
	Name      string          `json:"name"`
	Arguments json.RawMessage `json:"arguments"`
	Invalid   string          `json:"invalid,omitempty"`
}

type ToolSchemas

type ToolSchemas map[string]*jsonschema.Schema

func CompileTools

func CompileTools(tools []Tool) (ToolSchemas, error)

func (ToolSchemas) Check

func (s ToolSchemas) Check(call *ToolCall) error

func (ToolSchemas) Registered

func (s ToolSchemas) Registered(call ToolCall) error

func (ToolSchemas) Validate

func (s ToolSchemas) Validate(call ToolCall) error

type Turn

type Turn struct {
	OperationID     string          `json:"operation_id"`
	Model           string          `json:"model"`
	System          string          `json:"system"`
	Messages        []Message       `json:"messages"`
	Tools           []Tool          `json:"tools"`
	MaxOutputTokens int             `json:"max_output_tokens"`
	Continuation    json.RawMessage `json:"continuation,omitempty"`
	TimeoutMS       int64           `json:"timeout_ms"`
	Session         string          `json:"-"`
}

func (Turn) GoString

func (t Turn) GoString() string

func (Turn) LogValue

func (t Turn) LogValue() slog.Value

func (Turn) Request

func (t Turn) Request() TurnRequest

func (Turn) String

func (Turn) String() string

func (Turn) Valid

func (t Turn) Valid() bool

func (Turn) WithSkills

func (t Turn) WithSkills() (Turn, error)

type TurnRequest

type TurnRequest struct {
	OperationID     string
	Model           string
	System          string
	Messages        []Message
	Tools           []Tool
	MaxOutputTokens int
	Continuation    json.RawMessage
	Session         string
}

type TurnResult

type TurnResult struct {
	ProviderID   string          `json:"provider_id"`
	Text         string          `json:"text"`
	ToolCalls    []ToolCall      `json:"tool_calls"`
	Usage        Usage           `json:"usage"`
	Continuation json.RawMessage `json:"continuation,omitempty"`
	FinishReason string          `json:"finish_reason"`
}

func CollectTurn

func CollectTurn(ctx context.Context, p ModelProvider, t Turn) (TurnResult, error)

func (TurnResult) GoString

func (t TurnResult) GoString() string

func (TurnResult) LogValue

func (t TurnResult) LogValue() slog.Value

func (TurnResult) String

func (TurnResult) String() string

type Usage

type Usage struct {
	InputTokens         int64  `json:"input_tokens"`
	OutputTokens        int64  `json:"output_tokens"`
	CacheTokens         int64  `json:"cache_tokens"`
	CacheCreationTokens int64  `json:"cache_creation_tokens"`
	Known               bool   `json:"known"`
	Source              string `json:"source"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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