Documentation
¶
Overview ¶
Package jev is a client for System One decision models such as TypeSafe's Jev, served at POST {base}/systemone by OpenRouter and TypeSafe.
Types, validation and wire encoding are adapted from Denkeeper (github.com/Temikus/denkeeper, internal/llm), Apache-2.0.
Index ¶
- Constants
- Variables
- func BaseURL(provider, override string) (string, error)
- func EstimateTokens(state any, qs map[string]Question) (int, error)
- func SortedIDs[V any](qs map[string]V) []string
- func ValidateQuestions(qs map[string]Question) error
- type APIError
- type Answer
- type Client
- type ClientOption
- type Decider
- type Option
- type Question
- type QuestionType
- type Request
- type Response
- type Usage
Constants ¶
const ( MaxQuestionTokens = 32_000 MaxRequestTokens = 64_000 )
Upstream limits: state plus any one question, and the whole request.
Variables ¶
var ErrTooLarge = errors.New("decision input exceeds the request token limit")
ErrTooLarge is returned before any call when the input would exceed MaxRequestTokens. Input is never truncated.
var ErrValidation = errors.New("decision request failed validation")
ErrValidation is returned for HTTP 422: the provider rejected the request shape. Retrying cannot help.
Functions ¶
func BaseURL ¶
BaseURL resolves the API base for a provider name. A non-empty override (from LGTM_BASE_URL or the Action's base-url input, never from repo config) replaces it and must be https.
func EstimateTokens ¶
EstimateTokens estimates the input size of a call from its wire encoding.
func ValidateQuestions ¶
ValidateQuestions checks question shapes against the API limits so a malformed question fails before any call is made.
Types ¶
type APIError ¶
APIError is a non-200 reply. Message is the provider's short error text, capped at maxErrorLen; it is untrusted and must be escaped before display.
type Answer ¶
type Answer struct {
Type QuestionType `json:"type"`
Choice string `json:"choice,omitempty"`
Probabilities map[string]float64 `json:"probabilities,omitempty"`
Confidence float64 `json:"confidence,omitempty"`
Noul float64 `json:"noul,omitempty"`
Score float64 `json:"score,omitempty"`
}
Answer is the model's answer to one Question. Probabilities are keyed by option name for choice and by level index ("0", "1", ...) for score. Score is the expected level index, so it lies in [0, len(Levels)-1].
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client calls the System One endpoint.
func NewClient ¶
func NewClient(baseURL, apiKey string, opts ...ClientOption) *Client
NewClient returns a Client for baseURL (see BaseURL).
type ClientOption ¶
type ClientOption func(*Client)
ClientOption configures a Client.
func WithHTTPClient ¶
func WithHTTPClient(h *http.Client) ClientOption
WithHTTPClient replaces the default HTTP client.
type Decider ¶
Decider answers decision requests. Client implements it; tests may substitute a scripted fake.
type Option ¶
Option is a named choice and the definition bound to it. The model follows the name over the definition, so the two must never disagree.
type Question ¶
type Question struct {
Type QuestionType
Instructions string
Choices []Option // choice options in the order sent; for noul, optional "true"/"false"
Levels []string // score levels in order
}
Question is one typed question put to a decision model.
type QuestionType ¶
type QuestionType string
QuestionType is the answer shape a decision model is asked for.
const ( Choice QuestionType = "choice" // one of 2-255 named options Noul QuestionType = "noul" // probability the statement is true Score QuestionType = "score" // 2-10 ordered levels )