Documentation
¶
Overview ¶
Package jev evaluates named Noul, Choice, and Score questions with TypeSafe AI's Jev, either directly or through Vercel AI Gateway.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct {
StatusCode int
RequestID string
Code string
Message string
Body []byte // bounded raw response for structured validation errors; never logged by the SDK
}
APIError describes a non-success HTTP response. Use errors.As to inspect StatusCode, RequestID, and Code without parsing an error string.
type Answer ¶
type Answer struct {
Type QuestionType `json:"type"`
Noul float64 `json:"noul,omitempty"`
Choice string `json:"choice,omitempty"`
Score float64 `json:"score,omitempty"`
Confidence float64 `json:"confidence,omitempty"`
HasConfidence bool `json:"-"` // false when the provider did not supply confidence
Probabilities map[string]float64 `json:"probabilities,omitempty"`
Legend map[string]json.RawMessage `json:"legend,omitempty"`
}
Answer is discriminated by Type. Read only the fields for that type: Noul for "noul"; Choice, Probabilities, and Confidence for "choice"; Score, Legend, Probabilities, and Confidence for "score".
func (Answer) MarshalJSON ¶
MarshalJSON includes zero-valued results, which are meaningful answers.
func (*Answer) UnmarshalJSON ¶
UnmarshalJSON rejects incomplete answers instead of treating missing values as valid zero-probability or zero-score judgments.
type CallOptions ¶
type CallOptions struct {
Timeout time.Duration
Retry *RetryPolicy
Headers http.Header
}
CallOptions override client settings for one call. Context controls the total deadline, including retries and backoff.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client evaluates questions through the configured provider.
func NewClient ¶
NewClient constructs a client without making a network request. The API key must come from Config (or the environment when opted in). Only HTTPS and local loopback HTTP endpoints are accepted to keep credentials off plaintext links.
func (*Client) Ask ¶
func (c *Client) Ask( ctx context.Context, request Request, options ...CallOptions, ) (Response, error)
Ask is a convenience alias for SystemOne.
func (*Client) ListModels ¶
ListModels returns the models and aliases available to the account.
type Config ¶
type Config struct {
Provider Provider
APIKey string
BaseURL string
DefaultModel string
// ReadFromEnvironment opts into the selected provider's environment
// fallbacks. TypeSafe uses TYPESAFE_*; Vercel uses AI_GATEWAY_API_KEY.
ReadFromEnvironment bool
HTTPClient *http.Client
Timeout time.Duration // per attempt; default 10 seconds
Retry *RetryPolicy // nil uses the default policy; MaxRetries: 0 disables retries
Headers http.Header // optional additional headers; copied at construction
}
Config controls a client. Environment variables are never consulted unless ReadFromEnvironment is true. Explicit values take precedence when enabled. A Client and its HTTPClient may be shared by concurrent goroutines.
type GatewayOptions ¶
type GatewayOptions struct {
ZeroDataRetention bool `json:"zeroDataRetention,omitempty"`
DisallowPromptTraining bool `json:"disallowPromptTraining,omitempty"`
Only []string `json:"only,omitempty"`
Order []string `json:"order,omitempty"`
Tags []string `json:"tags,omitempty"`
User string `json:"user,omitempty"`
}
GatewayOptions contains the Vercel AI Gateway evaluation controls most relevant to Jev. A nil value sends no providerOptions field.
type Model ¶
type Model struct {
Name string `json:"name"`
Description string `json:"description"`
ReleaseDate string `json:"release_date"`
}
Model describes an available model or alias.
type NoulCriteria ¶
NoulCriteria optionally describes the yes and no outcomes.
type Question ¶
type Question struct {
Type QuestionType `json:"type"`
Instructions any `json:"instructions,omitempty"`
Criteria any `json:"criteria,omitempty"`
}
Question describes a judgment to make about the request's state. Instructions and Criteria may contain strings, objects, arrays, or nil. Prefer the Noul, Choice, and Score helpers for common questions.
func Choice ¶
Choice creates a question selecting one of the named options. Descriptions may be nil when a label needs no additional explanation.
func Noul ¶
func Noul(instructions any, criteria ...NoulCriteria) Question
Noul creates a yes/no question. Its answer's Noul field is P(yes).
type QuestionType ¶
type QuestionType string
QuestionType identifies the kind of answer a question requests.
const ( QuestionNoul QuestionType = "noul" QuestionChoice QuestionType = "choice" QuestionScore QuestionType = "score" )
type Request ¶
type Request struct {
State any `json:"state"`
Questions map[string]Question `json:"questions"`
Model string `json:"model,omitempty"`
// Gateway contains request options used only with ProviderVercel.
Gateway *GatewayOptions `json:"-"`
}
Request evaluates one or more named questions about JSON-compatible state. Set Model to override the client's default model for this call.
type Response ¶
type Response struct {
Model string `json:"model"`
Answers map[string]Answer `json:"answers"`
Usage Usage `json:"usage"`
RequestID string `json:"-"` // from the HTTP response header, if provided
Rounding *Rounding `json:"rounding,omitempty"`
Warnings []Warning `json:"warnings,omitempty"`
ProviderMetadata map[string]json.RawMessage `json:"provider_metadata,omitempty"`
}
Response contains the answers under the same keys as the request's questions.
type RetryPolicy ¶
type RetryPolicy struct {
MaxRetries int
InitialBackoff time.Duration // default 500ms
MaxBackoff time.Duration // default 5s
MaxRetryAfter time.Duration // default 60s; longer server delays use backoff
}
RetryPolicy controls automatic retries for connection errors, timeouts, HTTP 408, 429, and 5xx (including 529). MaxRetries counts attempts after the first; use &RetryPolicy{MaxRetries: 0} to disable retries. Zero-valued duration fields inherit their defaults.
type Rounding ¶
type Rounding struct {
ProbabilityDecimals *int `json:"probabilityDecimals,omitempty"`
ScoreDecimals *int `json:"scoreDecimals,omitempty"`
}
Rounding reports the precision applied by an evaluation provider.
type Warning ¶
type Warning struct {
Type string `json:"type"`
Feature string `json:"feature,omitempty"`
Details string `json:"details,omitempty"`
Setting string `json:"setting,omitempty"`
Message string `json:"message,omitempty"`
}
Warning describes a non-fatal provider compatibility or support issue.