jev

package
v0.25.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package jev provides a client for the TypeSafe "Jev" classification API (POST https://api.typesafe.ai/v1/systemone). It is used by internal/classify to classify documents (SMS, Gmail, call transcripts) into a segment (choice question) and a retention score (score question).

The client never logs request or response bodies — both may contain personal message content — only shapes and counts (see guides/... personal-data logging policy referenced by internal/worker/classification_worker.go).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChoiceAnswer

type ChoiceAnswer struct {
	Choice        string             `json:"choice"`
	Probabilities map[string]float64 `json:"probabilities"`
	Confidence    float64            `json:"confidence"`
}

ChoiceAnswer is Jev's answer to a QuestionChoice question.

func (ChoiceAnswer) Probability

func (a ChoiceAnswer) Probability() float64

Probability returns the probability Jev assigned to the chosen option, preferring Confidence (the top-choice probability field) and falling back to Probabilities[Choice] when Confidence is unset. Returns 0 when neither is available — callers must treat 0 as "no confidence", never as a disposable-eligible high-confidence answer.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a TypeSafe Jev API client.

func New

func New(apiKey string, httpClient *http.Client) *Client

New constructs a Client. apiKey may be empty — Enabled() reports false in that case and callers must not invoke Classify. httpClient, when nil, defaults to a client with a 15s timeout.

func NewForTest

func NewForTest(baseURL, apiKey string, httpClient *http.Client) *Client

NewForTest constructs a Client pointed at baseURL instead of the real Jev endpoint. Exported (not test-file-scoped) so other packages' tests — e.g. internal/classify's — can point a Classifier at an httptest.Server without internal/jev having to export its baseURL field for production use.

func (*Client) Classify

func (c *Client) Classify(ctx context.Context, state string, questions map[string]Question) (*Response, error)

Classify sends state and questions to the Jev API and returns the decoded response. Retries up to maxRetries times, with a linear backoff (attempt * retryBackoffUnit), on HTTP 429 and 5xx responses and on network-level errors. state and questions are never logged — only the resulting error (which must never embed response bodies) may surface to callers' logs.

func (*Client) Enabled

func (c *Client) Enabled() bool

Enabled reports whether the client has an API key configured. Callers (internal/classify.Classifier, internal/worker.ClassificationWorker) must check this before calling Classify and degrade to leaving documents unclassified when it is false.

type Question

type Question struct {
	Type         QuestionType `json:"type"`
	Instructions string       `json:"instructions"`
	// Criteria is map[string]string for QuestionChoice (option -> description)
	// or []string for QuestionScore (ordered score descriptions).
	Criteria any `json:"criteria"`
}

Question is one entry of a classification Request's Questions map.

type QuestionType

type QuestionType string

QuestionType identifies the shape of a Question's expected answer.

const (
	// QuestionChoice asks Jev to pick one option from Criteria (a
	// map[string]string of option -> description) and answers with
	// ChoiceAnswer.
	QuestionChoice QuestionType = "choice"
	// QuestionScore asks Jev to rate the state against an ordered list of
	// Criteria descriptions (index = score) and answers with ScoreAnswer.
	QuestionScore QuestionType = "score"
)

type Response

type Response struct {
	Answers map[string]json.RawMessage `json:"answers"`
	Usage   Usage                      `json:"usage"`
}

Response is a decoded POST /v1/systemone response. Individual answers are kept as raw JSON until Choice/Score is called with the expected question name, because the wire shape of answers[name] depends on the corresponding request Question's Type, which the Response itself does not carry.

func (*Response) Choice

func (r *Response) Choice(name string) (ChoiceAnswer, error)

Choice decodes the named answer as a ChoiceAnswer. Returns an error if the answer is missing or does not decode.

func (*Response) Score

func (r *Response) Score(name string) (ScoreAnswer, error)

Score decodes the named answer as a ScoreAnswer. Returns an error if the answer is missing or does not decode.

type ScoreAnswer

type ScoreAnswer struct {
	Score      float64        `json:"score"`
	Legend     map[string]any `json:"legend"`
	Confidence float64        `json:"confidence"`
}

ScoreAnswer is Jev's answer to a QuestionScore question.

type Usage

type Usage struct {
	InputTokens int `json:"input_tokens"`
}

Usage reports token accounting for a single Jev call.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL