decision

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 7 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 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

View Source
const (
	MaxQuestions     = 64
	MinChoiceOptions = 2
	MaxChoiceOptions = 255
	MinScoreLevels   = 2
	MaxScoreLevels   = 10
)

Limits of the public contract.

Variables

View Source
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

func ParseRequest(body []byte) (*Request, error)

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

Jump to

Keyboard shortcuts

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