Documentation
¶
Overview ¶
Package decision implements the JSON side of typed decisions (TypeSafe's "System One" API, POST /v1/systemone): validating the public request into an ordered runtime.DecisionInput, building the llama-server request body from it, mapping llama-server's answers back onto typed answers, and writing the public response.
Key order is part of the contract (proto design note 2026-10-03-decision-models): answers come back in request order and a model reads the options in the order the customer wrote them. Nothing in this package ever decodes `questions` or `criteria` into a Go map or marshals one: objects are read with a token decoder and written with an ordered writer.
Index ¶
- Constants
- Variables
- func ParseRuntimeResponse(body []byte, in *rt.DecisionInput) ([]rt.DecisionAnswer, rt.Usage, error)
- func RuntimeBody(in *rt.DecisionInput) ([]byte, error)
- func WriteResponse(model string, in *rt.DecisionInput, answers []rt.DecisionAnswer, ...) ([]byte, error)
- type Request
- type ValidationError
Constants ¶
const ( MaxQuestions = 64 MinChoiceOptions = 2 MaxChoiceOptions = 255 MinScoreLevels = 2 MaxScoreLevels = 10 )
Limits of the public contract.
Variables ¶
var ErrMalformed = errors.New("decision: malformed JSON body")
ErrMalformed is returned for a body that is not a JSON object at all (HTTP 400, like the other /v1 routes).
Functions ¶
func ParseRuntimeResponse ¶
func ParseRuntimeResponse(body []byte, in *rt.DecisionInput) ([]rt.DecisionAnswer, rt.Usage, error)
ParseRuntimeResponse maps llama-server's /v1/systemone response onto typed answers, one per question in question order, with probabilities ordered like the question's options (score: level index "0", "1", …). The runtime's `legend` is ignored: it is rebuilt from the request. Usage is input_tokens as prompt tokens; nothing is generated.
func RuntimeBody ¶
func RuntimeBody(in *rt.DecisionInput) ([]byte, error)
RuntimeBody builds the llama-server `POST /v1/systemone` body from a DecisionInput, writing `questions` and every `criteria` object in list order. The input was validated by whoever accepted the request (the gateway, or ParseRequest locally); this only refuses what would not be JSON at all, as an *rt.InvalidInputError.
func WriteResponse ¶
func WriteResponse(model string, in *rt.DecisionInput, answers []rt.DecisionAnswer, usage rt.Usage) ([]byte, error)
WriteResponse writes the public /v1/systemone response: `answers` and every `probabilities` / `legend` object in request order, `legend` rebuilt from the request's score criteria, and TypeSafe's usage names (output_tokens is always 0). answers must be one per question, in question order.
Types ¶
type Request ¶
type Request struct {
// Model is the requested model as written (a concrete id, a manifest
// id or its `flock/<id>` alias); the caller resolves it.
Model string
Input rt.DecisionInput
}
Request is a validated /v1/systemone request.
func ParseRequest ¶
ParseRequest validates a public /v1/systemone body against the contract and returns it with questions and options in document order. Errors are *ValidationError (422) or ErrMalformed (400).
type ValidationError ¶
type ValidationError struct{ Msg string }
ValidationError is a request the public contract rejects (HTTP 422). The message names the offending path (`questions.<id>.criteria`).
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string