decisions

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: BSD-2-Clause Imports: 24 Imported by: ? 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 decisions is a classifier backed by the Zoom Decisions API.

One Client holds one HTTP/2 connection pool, adds the auth and tracking headers, retries when Zoom is busy, and counts the tokens every request used. Several Classifiers can share one. A Classifier turns each question into Zoom's format and each answer into a result, through a Client.

See https://developers.zoom.us/docs/ai-services/decisions/

Index

Constants

View Source
const (
	// MaxQuestions is the most questions the Decisions API takes in one
	// request.
	MaxQuestions = 10
	// MaxChoiceOptions is the most options the Decisions API takes in one
	// choice question.
	MaxChoiceOptions = 255
	// MaxScoreLevels is the most levels the Decisions API takes in one score
	// question.
	MaxScoreLevels = 10
	// MaxImages is the most images the Decisions API takes in one request.
	MaxImages = 4
)
View Source
const (
	// DefaultURL is where questions are sent.
	DefaultURL = "https://api.zoom.us/v2/aiservices/decisions/decide"
	// DefaultModel is the decision model to ask: "zoom-decisions" or
	// "zoom-decisions-pro".
	DefaultModel = "zoom-decisions"
	// DefaultTimeout is how long to wait for an answer, retries included,
	// before giving up.
	DefaultTimeout = 10 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Choice

type Choice struct {
	// Value is the option, as the answer names it.
	Value string
	// Description is when the option applies, or nil when it is left out.
	Description *string
}

Choice is one option of a choice question in Zoom's own format.

type Classifier

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

Classifier answers questions by asking the Zoom Decisions API.

Structured state, instructions and descriptions are sent as JSON. 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.

One request takes up to MaxQuestions questions, a choice question up to MaxChoiceOptions options, and a score question up to MaxScoreLevels levels. The Decisions API can see images: up to MaxImages per call.

c, err := decisions.New(decisions.Config{APIKey: os.Getenv("ZOOM_AI_API_KEY")})

func New

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

New builds a Zoom Decisions classifier.

func (*Classifier) AskQuestions

func (c *Classifier) AskQuestions(
	ctx context.Context, state any, questions []classifier.Named[classifier.Question], inputs []classifier.Input,
) (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 decision model the questions go to.

func (*Classifier) Setup

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

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

func (*Classifier) SupportsImages

func (c *Classifier) SupportsImages() bool

SupportsImages reports that the Decisions API can see images.

type Client

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

Client is an HTTP client for the Zoom Decisions decide 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 Zoom answers 429 or 503, waiting at least as long as Zoom's Retry-After asks, within one time bound for the whole request. It counts the tokens every request used in Usage. Errors carry the reason Zoom gave and the request's x-zm-trackingid, which Zoom support uses to find it.

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

func NewClient

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

NewClient builds a Decisions API client.

func (*Client) Ask

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

Ask sends questions about one state and returns Zoom's answers, by question name and in Zoom's own format, and the tokens the request used.

input is what the questions are about, as the request's input: text, or user messages. questions are in Zoom's own format, each with a distinct name. options are other request fields, such as "enable_image_input": true.

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

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 Zoom.

It sends an OPTIONS request to the endpoint, which opens the connection without asking anything. Zoom has no request that checks the key without asking a question, so a bad key shows on the first question. It connects once: a client shared by several classifiers is asked by each of them, and only the first call sends anything.

It fails with an error wrapping classifier.ErrClassifier when Zoom could not be reached.

func (*Client) Model

func (c *Client) Model() string

Model is the decision model the questions go to.

func (*Client) Timeout

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

Timeout is how long the client waits for an answer, retries included.

func (*Client) URL

func (c *Client) URL() string

URL is where the questions are sent.

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 Zoom AI Services API key. Required.
	APIKey string `validate:"required"`
	// URL is the decide endpoint; empty uses DefaultURL. A plaintext http://
	// URL to a remote host logs a warning.
	URL string
	// Model is the decision model to ask, "zoom-decisions" or
	// "zoom-decisions-pro"; empty uses DefaultModel.
	Model string
	// Timeout is how long to wait for an answer, retries included, before
	// giving up; zero uses DefaultTimeout.
	Timeout time.Duration `validate:"min=0"`
	// MaxRetries is how many times to retry a request Zoom 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 Zoom AI Services 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
	// "ZoomDecisionsClassifier#<n>".
	Name string
	// Model is the decision model a client of its own asks, "zoom-decisions"
	// or "zoom-decisions-pro"; empty uses DefaultModel.
	Model string
	// URL is where a client of its own sends its questions; empty uses
	// DefaultURL.
	URL string
	// Timeout is how long a client of its own waits for an answer, retries
	// included; zero uses DefaultTimeout.
	Timeout time.Duration
}

Config configures a Zoom Decisions classifier.

type Question

type Question struct {
	// Type is "predicate", "choice" or "score".
	Type string
	// Name names the answer. Distinct within one request.
	Name string
	// Instructions is what is being asked, as text.
	Instructions string
	// Choices are the options of a choice question, in order.
	Choices []Choice
	// Levels are the labels of a score question's levels, lowest first.
	Levels []string
}

Question is one question in Zoom's own format.

func (Question) MarshalJSON

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

MarshalJSON implements json.Marshaler, writing the choices of a choice question and the levels of a score question.

type Usage

type Usage struct {
	// InputTokens is the tokens sent, as Zoom counts them in input_units.
	InputTokens int `json:"input_tokens"`
	// OutputTokens is the tokens received, one per question.
	OutputTokens int `json:"output_tokens"`
	// CachedInputTokens is the tokens sent that Zoom read from its cache.
	CachedInputTokens int `json:"cached_input_tokens"`
}

Usage is the tokens the Decisions API 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