Documentation
¶
Overview ¶
Package jev is a Go client for TypeSafe's System One API and its model, Jev.
Jev does not generate text. A request carries a state (text or JSON) and one or more named questions, and every answer comes back typed: a probability for a Noul, a picked option for a Choice, a position on a rubric for a Score, or a bounding box for a Box.
client, err := jev.New() // reads TYPESAFE_API_KEY
resp, err := client.SystemOne(ctx, jev.Request{
State: "I was charged twice. Please refund the extra charge.",
Questions: jev.Questions{
"billing": jev.Noul{Instructions: "Is this message about billing?"},
"urgency": jev.Score{
Instructions: "How urgent is this message?",
Criteria: []any{"Can wait", "This week", "Today"},
},
},
})
billing, err := resp.Noul("billing")
The API reference lives at https://docs.typesafe.ai/api.
Index ¶
Constants ¶
const ( DefaultBaseURL = "https://api.typesafe.ai" DefaultTimeout = 60 * time.Second EnvAPIKey = "TYPESAFE_API_KEY" EnvBaseURL = "TYPESAFE_BASE_URL" EnvModel = "TYPESAFE_DEFAULT_MODEL" )
Defaults and environment variables, shared with TypeSafe's official SDKs.
const ( ModelLatest = "jev-latest" ModelPreview = "jev-preview" )
Model aliases. An alias moves when a new model ships, so pin a versioned name such as "jev-1.14.0" when thresholds were tuned against one version.
const ( TypeNoul = "noul" TypeChoice = "choice" TypeScore = "score" TypeBox = "box" )
Question types as they appear in the type field of questions and answers.
Variables ¶
var Version = "dev"
Version is the SDK version, sent in the User-Agent header.
Functions ¶
Types ¶
type APIError ¶
type APIError struct {
StatusCode int
// Message is a readable summary of the error body.
Message string
// Body is the raw error body.
Body []byte
}
APIError is a non-2xx response from the API.
type Answer ¶
type Answer struct {
Type string `json:"type"`
// Noul is the probability of yes, from 0 to 1.
Noul *float64 `json:"noul,omitempty"`
// Choice is the option with the highest probability.
Choice string `json:"choice,omitempty"`
// Score is the probability-weighted level and may fall between levels.
Score *float64 `json:"score,omitempty"`
// Confidence is how sure the model is of a choice, score or box. It is
// nil for nouls, and for boxes when the model gives none.
Confidence *float64 `json:"confidence,omitempty"`
// Probabilities maps each option, or each level index for a score, to
// its probability.
Probabilities map[string]float64 `json:"probabilities,omitempty"`
// Legend maps each score level index to the criterion it stands for.
Legend map[string]any `json:"legend,omitempty"`
Box *BoxCoordinates `json:"box,omitempty"`
}
Answer is one typed answer. Type says which fields are set.
type Box ¶
type Box struct {
Instructions any
}
Box locates what Instructions describe in the request's image. It needs an image in the request and a model that supports boxes (Jev 1.14 or later).
func (Box) MarshalJSON ¶
type BoxCoordinates ¶
type BoxCoordinates struct {
Top float64 `json:"top"`
Bottom float64 `json:"bottom"`
Left float64 `json:"left"`
Right float64 `json:"right"`
}
BoxCoordinates are the edges of a box as fractions of the image, measured from the top and from the left.
type Choice ¶
Choice picks one option. Criteria maps each option name to a description of when it applies; a nil description lets the name speak for itself.
func (Choice) MarshalJSON ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client calls the System One API. It is safe for concurrent use.
func New ¶
New returns a client configured from options, falling back to the TYPESAFE_* environment variables and then to the defaults.
type Image ¶
type Image struct {
Data []byte
// Format is "png" or "jpg". [ReadImage] and [NewImage] detect it.
Format string
}
Image is a PNG or JPEG image to send with a request.
type Model ¶
type Model struct {
Name string `json:"name"`
Description string `json:"description"`
ReleaseDate string `json:"release_date"`
}
Model describes a model or alias available to the account.
type Noul ¶
type Noul struct {
Instructions any
// Criteria optionally clarifies what counts as yes and no.
Criteria *NoulCriteria
}
Noul asks a yes/no question and is answered with the probability of yes.
func (Noul) MarshalJSON ¶
type NoulCriteria ¶
NoulCriteria describes what counts as a yes (True) and a no (False).
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithAPIKey ¶
WithAPIKey sets the API key instead of reading TYPESAFE_API_KEY.
func WithBaseURL ¶
WithBaseURL points the client at another API host, such as a proxy.
func WithHTTPClient ¶
WithHTTPClient replaces the HTTP client, for custom transports or proxies.
func WithTimeout ¶
WithTimeout sets the timeout of each HTTP attempt.
func WithUserAgent ¶
WithUserAgent prefixes the User-Agent header with your application's name.
type Question ¶
type Question interface {
Type() string
}
Question is one typed judgment about a request's state. Instructions and criteria accept a string, or any JSON-encodable object or array.
type Questions ¶
Questions maps the names you choose to questions. Names key the answers and are never shown to the model, so put the whole question in Instructions.
type Request ¶
type Request struct {
// Model overrides the client's default model for this request.
Model string `json:"model,omitempty"`
// State is the content every question refers to: a string, or any
// JSON-encodable object or array.
State any `json:"state"`
// Questions maps your names to the questions to ask.
Questions Questions `json:"questions"`
// Images maps a reference string to an image. Write the reference
// anywhere a string can go in State, Instructions or Criteria and the
// model sees the image in its place. Use [NewRef] for references that
// cannot collide with ordinary text.
Images map[string]Image `json:"-"`
// LongContext raises the context limits for this request. It is slower
// and less accurate, so turn it on only when the state needs it.
LongContext bool `json:"-"`
}
Request is one System One call: a state and the questions to ask about it.
type Response ¶
type Response struct {
// Model is the versioned model that answered, even when the request
// named an alias such as jev-latest.
Model string `json:"model"`
Answers map[string]Answer `json:"answers"`
Usage Usage `json:"usage"`
}
Response holds the answers to one request, keyed by question name.
type RetryPolicy ¶
type RetryPolicy struct {
// MaxRetries is the number of retries after the first attempt; 0
// disables retries.
MaxRetries int
// InitialBackoff is the wait before the first retry; it doubles each
// time up to MaxBackoff.
InitialBackoff time.Duration
MaxBackoff time.Duration
// Jitter randomizes each wait by up to this fraction, so clients that
// were throttled together do not retry together.
Jitter float64
}
RetryPolicy controls retries of rate-limited, overloaded and failed requests. The defaults match TypeSafe's official SDKs.
func DefaultRetryPolicy ¶
func DefaultRetryPolicy() RetryPolicy
DefaultRetryPolicy returns the policy a new client uses.
type Score ¶
Score rates the state on an ordered rubric. The position of each level in Criteria is its score, starting at zero.
func (Score) MarshalJSON ¶
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
jev
command
Command jev asks TypeSafe's Jev typed questions from the command line and serves them as MCP tools.
|
Command jev asks TypeSafe's Jev typed questions from the command line and serves them as MCP tools. |
|
internal
|
|
|
cli
Package cli implements the jev command.
|
Package cli implements the jev command. |
|
mcpserver
Package mcpserver exposes Jev as Model Context Protocol tools.
|
Package mcpserver exposes Jev as Model Context Protocol tools. |