jev

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: BSD-2-Clause Imports: 17 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 is a classifier backed by Jev, TypeSafe's hosted classification model.

One Client holds one HTTP/2 connection pool, adds the auth header, retries when Jev is busy, and counts the tokens every request used. Several Classifiers can share one. A Classifier turns each question into a request and each reply into a result, through a Client.

Index

Constants

View Source
const (
	// DefaultBaseURL is where the API is served.
	DefaultBaseURL = "https://api.typesafe.ai"
	// DefaultModel is the Jev model to ask. Pinned so thresholds tuned against
	// it hold.
	DefaultModel = "jev-1.13.0"
	// DefaultTimeout is how long to wait for a reply before giving up.
	DefaultTimeout = 10 * time.Second
)
View Source
const MaxChoiceOptions = 255

MaxChoiceOptions is the most options Jev takes in one choice question.

Variables

This section is empty.

Functions

This section is empty.

Types

type Classifier

type Classifier struct {
	*classifier.Base
	// contains filtered or unexported fields
}

Classifier answers questions by asking Jev.

Jev's probabilities are calibrated. Build one with an API key to get a client of its own, or pass a Client to share one between several classifiers. A client the classifier created is closed in Cleanup; a shared one is left to whoever made it.

client, err := jev.NewClient(jev.ClientConfig{APIKey: key})
turn, err := jev.New(jev.Config{Client: client})
voicemail, err := jev.New(jev.Config{Client: client})

func New

func New(cfg Config) (*Classifier, error)

New builds a Jev classifier.

func (*Classifier) AskQuestions

func (c *Classifier) AskQuestions(
	ctx context.Context, state any, questions []classifier.Named[classifier.Question],
) (map[string]classifier.Result, *frames.LLMTokenUsage, error)

AskQuestions implements classifier.Asker, answering the questions in one request.

func (*Classifier) Cleanup

func (c *Classifier) Cleanup(ctx context.Context) error

Cleanup closes the client if this classifier created it.

func (*Classifier) Client

func (c *Classifier) Client() *Client

Client is the client this classifier asks through.

func (*Classifier) Model

func (c *Classifier) Model() string

Model is the Jev model the questions go to.

func (*Classifier) Setup

func (c *Classifier) Setup(ctx context.Context) error

Setup opens the connection to Jev ahead of the first question. A connection that cannot be opened now is only a warning: the first question opens it itself.

type Client

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

Client is an HTTP client for Jev's systemone endpoint.

It holds one HTTP/2 connection pool, so many small requests share a connection and can be in flight at the same time. The connection is kept open between questions, so a gap between them does not cost a new TLS handshake. It retries with backoff when Jev answers 429 or 529, and counts the tokens every request used in Usage.

Connect opens the connection ahead of the first question, and Close releases it.

func NewClient

func NewClient(cfg ClientConfig) (*Client, error)

NewClient builds a Jev client.

func (*Client) Ask

func (c *Client) Ask(
	ctx context.Context, state any, questions []NamedQuestion,
) (map[string]map[string]any, Usage, error)

Ask sends questions about one state and returns Jev's answers, by the same names and in Jev's own format, and the tokens the request used.

It fails with an error wrapping classifier.ErrClassifier when Jev rejected the request, kept refusing it because it was busy, could not be reached, or left a question unanswered.

func (*Client) BaseURL

func (c *Client) BaseURL() string

BaseURL is where the questions are sent.

func (*Client) Close

func (c *Client) Close()

Close closes the connection pool.

func (*Client) Connect

func (c *Client) Connect(ctx context.Context) error

Connect opens the connection to Jev.

It lists the models, the cheapest request there is, so the first question finds the connection already open. It connects once: a client shared by several classifiers is asked by each of them, and only the first call sends anything.

func (*Client) Model

func (c *Client) Model() string

Model is the Jev model the questions go to.

func (*Client) Timeout

func (c *Client) Timeout() time.Duration

Timeout is how long the client waits for a reply.

func (*Client) Usage

func (c *Client) Usage() Usage

Usage is the tokens used so far, over every request.

type ClientConfig

type ClientConfig struct {
	// APIKey is the Jev API key. Required.
	APIKey string `validate:"required"`
	// BaseURL is where the API is served; empty uses DefaultBaseURL.
	BaseURL string
	// Model is the Jev model to ask; empty uses DefaultModel, pinned so
	// thresholds tuned against it keep holding. "jev-latest" follows TypeSafe's
	// newest release.
	Model string
	// Timeout is how long to wait for a reply before giving up; zero uses
	// DefaultTimeout.
	Timeout time.Duration `validate:"min=0"`
	// MaxRetries is how many times to retry a request Jev refused because it
	// was busy; nil uses 3.
	MaxRetries *int `validate:"omitempty,min=0"`
	// HTTPClient sends the requests; nil builds one that keeps HTTP/2
	// connections open between questions.
	HTTPClient *http.Client
}

ClientConfig configures a Client.

type Config

type Config struct {
	// APIKey is the Jev API key, when the classifier should have a client of
	// its own. One of APIKey and Client is required.
	APIKey string
	// Client is a client to share between several classifiers.
	Client *Client
	// Name names the classifier in its metrics; empty uses "JevClassifier#<n>".
	Name string
	// Model is the Jev model a client of its own asks; empty uses DefaultModel.
	Model string
	// BaseURL is where a client of its own sends its questions; empty uses
	// DefaultBaseURL.
	BaseURL string
	// Timeout is how long a client of its own waits for an answer; zero uses
	// DefaultTimeout.
	Timeout time.Duration
}

Config configures a Jev classifier.

type NamedQuestion

type NamedQuestion struct {
	Name     string
	Question Question
}

NamedQuestion is a question in Jev's format with the name its answer comes back under.

type Question

type Question struct {
	// Type is "noul", "choice" or "score".
	Type string
	// Instructions is what is being asked.
	Instructions any
	// Criteria is what counts as each answer, or nil when the question leaves
	// it open.
	Criteria any
}

Question is one question in Jev's own format.

func (Question) MarshalJSON

func (q Question) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler, leaving criteria out when there are none.

type Usage

type Usage struct {
	// InputTokens is the tokens sent.
	InputTokens int `json:"input_tokens"`
	// OutputTokens is the tokens received.
	OutputTokens int `json:"output_tokens"`
}

Usage is the tokens Jev used: for one request, or over every request a client sent.

Jump to

Keyboard shortcuts

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