requestparams

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 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

Overview

Package requestparams applies operator-configured request parameters to translated inference requests. A virtual model or model policy may carry two parameter sets: defaults, filled in only when the client omitted the key, and forced params, which replace the client's value. Keys use Chat Completions spelling; provider adapters translate them exactly as they translate client-sent values.

Index

Constants

View Source
const (
	MaxKeys   = 64
	MaxKeyLen = 64
	MaxBytes  = 16 << 10
)

Limits bounding a configured set, so a row cannot grow a request body without bound or stall validation.

Variables

This section is empty.

Functions

func ApplyChat

func ApplyChat(req *core.ChatRequest, defaults, params Set) (*core.ChatRequest, error)

ApplyChat returns req with defaults filled in and params forced. The request is never mutated: the result is req itself when both sets are empty and a shallow copy otherwise.

func ApplyResponses

func ApplyResponses(req *core.ResponsesRequest, defaults, params Set) (*core.ResponsesRequest, error)

ApplyResponses is ApplyChat for the Responses API. Keys keep Chat Completions spelling: any token-limit spelling sets max_output_tokens. Chat members the Responses API rejects are skipped, response_format and verbosity included: a format for this API is set through text.

func CapChatTokens added in v0.2.7

func CapChatTokens(req *core.ChatRequest, ceilings Ceilings) (*core.ChatRequest, error)

CapChatTokens returns req with its output token limit within the token ceiling. Adapters read max_tokens and, where that is unset, max_completion_tokens, so a request that sets neither gets max_tokens: its own max_output_tokens when that is within the ceiling (chat has no such member, so alone it would limit nothing upstream), otherwise the ceiling, or the model's own maximum when that is lower. Every spelling the request does carry is lowered to the ceiling in place, one inside extra_body included. The request is never mutated: the result is req itself when it is already within the ceiling and spells no limit in another letter case.

func CapResponsesTokens added in v0.2.7

func CapResponsesTokens(req *core.ResponsesRequest, ceilings Ceilings) (*core.ResponsesRequest, error)

CapResponsesTokens is CapChatTokens for the Responses API, whose only limit is max_output_tokens: a request that sets it in a chat spelling alone gets it there.

func Disjoint

func Disjoint(defaults, params Set) error

Disjoint rejects a key configured in both sets of one row, where the forced value would silently make the default dead.

func EffortRank added in v0.2.7

func EffortRank(effort string) int

EffortRank returns the position of effort on ReasoningEffortLevels, or -1 for a value the scale does not know. Spelling is matched as clients send it: trimmed and case-insensitive.

func NormalizeReasoningEffort added in v0.2.7

func NormalizeReasoningEffort(field, effort string) (string, error)

NormalizeReasoningEffort trims and lower-cases a configured effort, rejecting values outside ReasoningEffortLevels. Empty stays empty. field names the setting in the message.

func ReasoningEffortLevels added in v0.2.7

func ReasoningEffortLevels() []string

ReasoningEffortLevels returns the common reasoning effort scale, lowest first. The result is the caller's own copy, so the scale validation and ranking depend on cannot be changed from outside.

func ToAny added in v0.2.4

func ToAny(set Set) (map[string]any, error)

ToAny decodes a set into the object FromAny encodes, for writing it out as configuration. An integer stays an integer rather than becoming a float, and a nil value, which strips its key, stays nil.

Types

type Ceilings added in v0.2.7

type Ceilings struct {
	// ReasoningEffort is the highest level of ReasoningEffortLevels allowed.
	ReasoningEffort string
	// OutputTokens is the highest output token limit allowed, in any of the
	// token-limit spellings.
	OutputTokens int
	// ModelOutputTokens is the most output tokens the attempt's model
	// produces, when the catalogue knows it. It is no ceiling: a request that
	// sends no limit gets the lower of it and OutputTokens, because a ceiling
	// above what the model takes would be refused upstream as a limit.
	ModelOutputTokens int
}

Ceilings are upper bounds on what one provider attempt may ask for. A ceiling lowers a request's value and never raises it. The token ceiling also fills in a limit a request leaves out, since an omitted limit is no limit at all; the effort ceiling adds nothing, so it never switches reasoning on. Zero values mean no ceiling.

func (Ceilings) IsZero added in v0.2.7

func (c Ceilings) IsZero() bool

IsZero reports whether no ceiling is set.

func (Ceilings) Tighten added in v0.2.7

func (c Ceilings) Tighten(other Ceilings) Ceilings

Tighten returns the lower of each ceiling in c and other, so combining ceilings can only narrow them.

type Overrides

type Overrides struct {
	ReasoningEffort string
	Defaults        Set
	Params          Set
	// Ceilings apply last, to the request as the fields above left it, so
	// they bound a forced or defaulted value as they bound the client's.
	Ceilings Ceilings
}

Overrides is everything the operator configures for one provider attempt: the forced reasoning effort and both parameter sets, already merged along the route the request took, and the ceilings that bound the result.

func (Overrides) Forces added in v0.2.7

func (o Overrides) Forces() bool

Forces reports whether a reasoning effort or a parameter set is configured, which rewrites every request; ceilings alone rewrite only a request that exceeds them or sets no output token limit.

func (Overrides) IsZero

func (o Overrides) IsZero() bool

IsZero reports whether nothing is configured.

func (Overrides) Layer

func (o Overrides) Layer(over Overrides) Overrides

Layer returns o with the deeper over applied on top: a non-empty effort replaces, and parameter sets merge per key with over winning. Precedence holds across the two sets: a key over configures as a default stops being forced by a shallower row, and one it forces stops being a shallower row's default. Ceilings have no winner: the tightest of both stays.

type Set

type Set map[string]json.RawMessage

Set maps body-level parameter names to their JSON values. A nil value in a forced set removes the key from the request.

func Clone

func Clone(set Set) Set

Clone deep-copies a set so stored rows are never shared with callers.

func FromAny

func FromAny(values map[string]any) (Set, error)

FromAny encodes a decoded YAML or JSON object into a set.

func Merge

func Merge(base, over Set) Set

Merge returns base with over's keys added, over winning on conflict. Sets are treated as immutable: the result shares no map with either input when both are non-empty, and is the non-empty input otherwise.

func Normalize

func Normalize(field string, set Set, allowNull bool) (Set, error)

Normalize validates a configured set and returns it in canonical form: trimmed keys, compact values, and nil for an empty set. allowNull admits null values, which a forced set uses to strip a key. field names the setting in messages.

Jump to

Keyboard shortcuts

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