Help us shape the future of Go! Take the 2026 Go Developer Survey

systemone

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package systemone is a client for TypeSafe's System One API, which answers typed questions about a state: a Choice selects one supplied option, a Score rates against supplied levels, and a Noul is the probability that a proposition holds. It serves any TypeSafe-compatible endpoint, such as TypeSafe's own or OpenRouter's, and depends only on the standard library.

Index

Constants

View Source
const (
	MaxChoiceOptions = 255
	MaxScoreLevels   = 10
)

The API's request limits.

View Source
const DefaultBaseURL = "https://api.typesafe.ai"

DefaultBaseURL is TypeSafe's own API.

Variables

This section is empty.

Functions

This section is empty.

Types

type Answer

type Answer struct {
	Kind          Kind               `json:"type"`
	Choice        string             `json:"choice,omitempty"`
	Score         float64            `json:"score,omitempty"`
	Noul          float64            `json:"noul,omitempty"`
	Probabilities map[string]float64 `json:"probabilities,omitempty"`
	// Confidence is derived from the answer's distribution by the API. It
	// is not a verified probability of being correct.
	Confidence float64 `json:"confidence,omitempty"`
}

Answer is one validated answer, in the API's own field names. Probabilities map each Choice option, or each Score level index as a decimal string, to its probability.

type Client

type Client struct {
	BaseURL, Model, APIKey string
	HTTPClient             *http.Client
}

Client calls a TypeSafe-compatible API at BaseURL, an empty BaseURL being DefaultBaseURL. Requests go to <BaseURL>/v1/systemone with APIKey as the bearer credential, which never follows a redirect. A nil HTTPClient uses http.DefaultClient's transport.

func (Client) Evaluate

func (c Client) Evaluate(ctx context.Context, r Request) (Response, error)

Evaluate asks the model r's questions and validates the answers. Every error is an *Error. The context bounds the request; Evaluate does not retry.

type Error

type Error struct {
	Kind       ErrorKind
	StatusCode int
	RetryAfter time.Duration
	Message    string
}

Error is a failed request. Message never contains the API key. RetryAfter is the endpoint's requested delay, if any.

func (*Error) Error

func (e *Error) Error() string

type ErrorKind

type ErrorKind string

ErrorKind says why a request produced no usable response.

const (
	// KindInvalidRequest is a request refused before sending: it breaks the
	// API's limits, or the client has no API key.
	KindInvalidRequest ErrorKind = "invalid_request"
	// KindUnauthorized is an API key the endpoint refused.
	KindUnauthorized ErrorKind = "unauthorized"
	// KindRejected is any other request the endpoint refused, such as an
	// invalid or oversized one, or a redirect.
	KindRejected    ErrorKind = "rejected"
	KindRateLimited ErrorKind = "rate_limited"
	// KindUnavailable is a network failure or a server error.
	KindUnavailable ErrorKind = "unavailable"
	KindTimeout     ErrorKind = "timeout"
	KindCancelled   ErrorKind = "cancelled"
	// KindMalformed is a response that does not answer the questions in the
	// shape they require.
	KindMalformed ErrorKind = "malformed_response"
)

type Kind

type Kind string

Kind is a question type.

const (
	KindChoice Kind = "choice"
	KindScore  Kind = "score"
	KindNoul   Kind = "noul"
)

type Option

type Option struct {
	Name        string
	Description any
}

Option is one choice. Description is optional rubric text.

type Question

type Question struct {
	Kind         Kind
	Instructions any
	// Options are a Choice's options, in the order the model sees them.
	Options []Option
	// Levels are a Score's ordered level descriptions, lowest first.
	Levels []any
	// Yes and No optionally describe what each Noul answer means.
	Yes, No any
}

Question is one typed question. Instructions and descriptions are strings or JSON values; a structured value can hold the question in one field and the data it refers to in others.

func Choice

func Choice(instructions any, options ...Option) Question

Choice asks the model to select one of options.

func Noul

func Noul(instructions any) Question

Noul asks the model for the probability that a proposition holds.

func Score

func Score(instructions any, levels ...any) Question

Score asks the model to rate the state on levels, lowest first.

func (Question) MarshalJSON

func (q Question) MarshalJSON() ([]byte, error)

MarshalJSON writes the API's wire form. A Choice's criteria keep the options' order.

type Request

type Request struct {
	// State is a string or a JSON value.
	State     any
	Questions map[string]Question
}

Request is a state and the questions asked of it, keyed by an ID the caller chooses. Every question is evaluated independently against the same state.

func (Request) Body

func (r Request) Body(model string) ([]byte, error)

Body is the JSON request body the API receives when model is asked r.

func (Request) Validate

func (r Request) Validate() error

Validate checks the request against the API's limits, so a request that would be refused is never sent.

type Response

type Response struct {
	Model   string            `json:"model"`
	Answers map[string]Answer `json:"answers"`
	Usage   Usage             `json:"usage"`
}

Response is a validated answer to every question of a request. Model is the versioned model that answered, which may differ from an alias asked for.

type Usage

type Usage struct {
	InputTokens  int     `json:"input_tokens"`
	OutputTokens int     `json:"output_tokens"`
	CostUSD      float64 `json:"cost_usd,omitempty"`
	CostKnown    bool    `json:"cost_known,omitempty"`
}

Usage is what one request consumed. CostKnown says the endpoint reported CostUSD, as gateways such as OpenRouter may.

Jump to

Keyboard shortcuts

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