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 ¶
const ( MaxChoiceOptions = 255 MaxScoreLevels = 10 )
The API's request limits.
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"`
Score float64 `json:"score"`
Noul float64 `json:"noul"`
Probabilities map[string]float64 `json:"probabilities"`
// Confidence is derived from the answer's distribution by the API. It
// is not a verified probability of being correct.
Confidence float64 `json:"confidence"`
}
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.
func (Answer) MarshalJSON ¶ added in v1.0.3
MarshalJSON writes the fields a's kind carries, zero values included, so a Score of 0 or a Noul of 0 reads back as given.
type 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.
type Error ¶
Error is a failed request. Message never contains the API key. RetryAfter is the endpoint's requested delay, if any.
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 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. 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 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 (Question) MarshalJSON ¶
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.
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.