presets

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package presets owns reusable inference configuration presets and persistence.

Index

Constants

View Source
const (
	SortPrice      = "price"
	SortLatency    = "latency"
	SortThroughput = "throughput"
	SortSpread     = "spread"
)

Provider sort orders a preset may store. They mirror the OpenRouter wire values; "throughput" routes by measured latency, Starport's closest signal. "spread" is the Starport extension that balances traffic across the routes whose ranking metric sits inside one band.

View Source
const (
	// StorageSchemaVersion identifies the only preset schema.
	StorageSchemaVersion = 1
	// StoragePrefix is the preset v1 namespace.
	StoragePrefix = "presets:v1:name:"
)
View Source
const (
	// RevisionPrefix is the immutable preset revision namespace. Each
	// save stores its record here beside the head, keyed by name and a
	// zero-padded revision number so a prefix scan lists in order.
	RevisionPrefix = "presets:v1:revision:"
)

Variables

View Source
var (
	// ErrRepositoryRequired reports an absent preset storage adapter.
	ErrRepositoryRequired = errors.New("preset storage is required")
	// ErrNotFound reports an absent preset.
	ErrNotFound = errors.New("preset not found")
	// ErrConflict reports a preset revision conflict.
	ErrConflict = errors.New("preset revision conflict")
	// ErrCorruptRecord reports invalid durable preset data.
	ErrCorruptRecord = errors.New("preset record is invalid")
	// ErrNameImmutable reports an attempted preset-name change.
	ErrNameImmutable = errors.New("preset name is immutable")
)
View Source
var ErrInvalidPreset = errors.New("invalid preset")

ErrInvalidPreset reports a preset that fails validation.

Functions

This section is empty.

Types

type Config added in v1.1.0

type Config struct {
	Model            string               `json:"model,omitempty"`
	Models           []string             `json:"models,omitempty"`
	Provider         *ProviderPreferences `json:"provider,omitempty"`
	System           string               `json:"system,omitempty"`
	Temperature      *float32             `json:"temperature,omitempty"`
	TopP             *float32             `json:"top_p,omitempty"`
	PresencePenalty  *float32             `json:"presence_penalty,omitempty"`
	FrequencyPenalty *float32             `json:"frequency_penalty,omitempty"`
	MaxTokens        *int                 `json:"max_tokens,omitempty"`
	Seed             *int                 `json:"seed,omitempty"`
	Stop             []string             `json:"stop,omitempty"`
}

Config is the typed preset subset a request may inherit: model selection, provider preferences, a system prompt, and sampling overrides. Fields the request supplies win over preset fields.

func (Config) Clone added in v1.1.0

func (c Config) Clone() Config

Clone returns a deep copy of the config.

func (Config) IsZero added in v1.1.0

func (c Config) IsZero() bool

IsZero reports whether the config carries no settings at all.

type Preset

type Preset struct {
	Name        string    `json:"name"`
	Description string    `json:"description,omitempty"`
	Config      Config    `json:"config"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

Preset is one reusable inference configuration. The name is the reference: requests select a preset with "@preset/<name>" or a "preset" body field.

func (Preset) Validate

func (p Preset) Validate() error

Validate checks preset invariants.

type ProviderPreferences added in v1.1.0

type ProviderPreferences struct {
	Order          []string `json:"order,omitempty"`
	Only           []string `json:"only,omitempty"`
	Ignore         []string `json:"ignore,omitempty"`
	AllowFallbacks *bool    `json:"allow_fallbacks,omitempty"`

	// Sort selects the route ordering; empty keeps the server default.
	Sort string `json:"sort,omitempty"`
	// Price caps are USD per million tokens, matching the wire shape.
	// Zero means no cap.
	MaxPromptPricePer1M     float64 `json:"max_prompt_price_per_1m,omitempty"`
	MaxCompletionPricePer1M float64 `json:"max_completion_price_per_1m,omitempty"`
}

ProviderPreferences is the preset-owned provider routing policy.

type Record

type Record struct {
	Revision uint64
	Preset   Preset
}

Record is one versioned preset repository value. Revision carries one meaning with two uses: it is the preset's place in its immutable history, and because every save is a new revision, the same number is the optimistic-concurrency token an update must name. The two never diverge by construction.

type Repository

type Repository interface {
	Create(context.Context, Preset) (Record, error)
	Get(context.Context, string) (Record, error)
	List(context.Context, int) ([]Record, error)
	Update(context.Context, Preset, uint64) (Record, error)
	Delete(context.Context, string, uint64) error
	// History answers stored revisions newest-first, up to limit.
	History(ctx context.Context, name string, limit int) ([]Record, error)
	// GetRevision answers one pinned revision verbatim.
	GetRevision(ctx context.Context, name string, revision uint64) (Record, error)
	// Rollback saves a new head revision that copies an old one. The
	// expected revision names the head the caller read, like Update.
	Rollback(ctx context.Context, name string, toRevision, expectedRevision uint64) (Record, error)
}

Repository is the durable preset contract. Every save writes an immutable revision snapshot beside the head, so a request can pin a revision and an operator can roll back to one.

func Open

func Open(store storage.KVStore) (Repository, error)

Open returns a storage-backed preset repository.

Jump to

Keyboard shortcuts

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