Documentation
¶
Overview ¶
Package jev provides a Go SDK for TypeSafe's Jev API.
Index ¶
Constants ¶
const DefaultModel = "jev-latest"
DefaultModel is used when a request does not specify a model.
Variables ¶
var ( ErrNilClientOpts = errors.New("jev: client option must not be nil") ErrAPIKeyMissing = errors.New("jev: API key is required; set TYPESAFE_API_KEY or use WithAPIKey") ErrNilHTTPClient = errors.New("jev: HTTP client must not be nil") ErrInvalidBaseURL = errors.New("jev: invalid base URL") )
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct {
StatusCode int
Header http.Header
Body []byte
// contains filtered or unexported fields
}
APIError represents a non-successful HTTP reponse from the API.
type Answer ¶
type Answer interface {
// contains filtered or unexported methods
}
Answer represents one of the supported evaluation results.
type ChoiceAnswer ¶
type ChoiceAnswer struct {
Choice string `json:"choice"` // The key of the selected option
Probabilities map[string]float64 `json:"probabilities"`
Confidence float64 `json:"confidence"`
}
Choice answer contains a selected option and its distribution.
type ChoiceQuestion ¶
ChoiceQuestion asks the model to select one named option.
see https://docs.typesafe.ai/primitives/choice
func (ChoiceQuestion) MarshalJSON ¶
func (q ChoiceQuestion) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client holds all the configuration for API requests
func NewClient ¶
NewClient constructs a Jev client from defaults and provided options.
Reads TYPESAFE_API_KEY unless WithAPIKey is provided.
func (*Client) SystemOne ¶
func (c *Client) SystemOne(ctx context.Context, req SystemOneRequest) (*SystemOneResponse, error)
SystemOne calls the API to evaluate the set of questions. Performs one attempt, no retry loop.
type NoulAnswer ¶
type NoulAnswer struct {
Noul float64 `json:"noul"` // 0-1
}
NoulAnswer contains the probability that a statement is true.
type NoulCriteria ¶
NoulCriteria provides descriptions for the two possible outcomes.
type NoulQuestion ¶
type NoulQuestion struct {
Instructions any
Criteria *NoulCriteria
}
NoulQuestion asks for the probability that a statement is true.
see https://docs.typesafe.ai/primitives/noul
func (NoulQuestion) MarshalJSON ¶
func (q NoulQuestion) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler
type Option ¶
type Option func(*clientConfig)
Option configures a client during NewClient
func WithAPIKey ¶
WithAPIKey overrides the API key read from TYPESAFE_API_KEY.
func WithHTTPClient ¶
WithHTTPClient replaces the default HTTP Client.
type ScoreAnswer ¶
type ScoreAnswer struct {
Score float64 `json:"score"`
Legend map[string]string `json:"legend"`
Probabilities map[string]float64 `json:"probabilities"`
Confidence float64 `json:"confidence"`
}
ScoreAnswer contains a numeric score.
type ScoreQuestion ¶
ScoreQuestion asks the model to evaluate the state against ordered levels.
see https://docs.typesafe.ai/primitives/score
func (ScoreQuestion) MarshalJSON ¶
func (q ScoreQuestion) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
type SystemOneRequest ¶
type SystemOneRequest struct {
Model string `json:"model"` // Defaults to jev-latest
State any `json:"state"` // The content evaluated by the questions
Questions map[string]Question `json:"questions"`
}
SystemOneRequest contains the input for one evaluation.
func (SystemOneRequest) MarshalJSON ¶
func (r SystemOneRequest) MarshalJSON() ([]byte, error)
MarshalJSON encodes an evaluation request.
type SystemOneResponse ¶
type SystemOneResponse struct {
Model string `json:"model"`
Answers map[string]Answer `json:"answers"`
Usage Usage `json:"usage"`
}
SystemOneResponse contains an evaluation's results and metadata.
func (*SystemOneResponse) UnmarshalJSON ¶
func (r *SystemOneResponse) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes an evaluation response.