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
- func ApplyChat(req *core.ChatRequest, defaults, params Set) (*core.ChatRequest, error)
- func ApplyResponses(req *core.ResponsesRequest, defaults, params Set) (*core.ResponsesRequest, error)
- func CapChatTokens(req *core.ChatRequest, ceilings Ceilings) (*core.ChatRequest, error)
- func CapResponsesTokens(req *core.ResponsesRequest, ceilings Ceilings) (*core.ResponsesRequest, error)
- func Disjoint(defaults, params Set) error
- func EffortRank(effort string) int
- func NormalizeReasoningEffort(field, effort string) (string, error)
- func ReasoningEffortLevels() []string
- func ToAny(set Set) (map[string]any, error)
- type Ceilings
- type Overrides
- type Set
Constants ¶
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 ¶
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
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
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.
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.
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
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) Layer ¶
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 Merge ¶
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.