decider

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 15 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 decider asks a language model typed questions at points where the crawler would otherwise guess. Answers are validated against what the crawler offers, so the model can never introduce values or actions of its own.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotRecorded    = errors.New("decider: answer not recorded")
	ErrBudgetExceeded = errors.New("decider: call budget exceeded")
	// ErrUnavailable means the provider rejected the url, model or key, or the
	// account is out of credit, so retrying cannot help.
	ErrUnavailable = errors.New("decider: provider unavailable")
)

Functions

This section is empty.

Types

type Answer

type Answer struct {
	Bool   bool    `json:"bool,omitempty"`
	Choice string  `json:"choice,omitempty"`
	Score  float64 `json:"score,omitempty"`
}

Answer holds the field matching the question kind. Score is in [0, 1].

type Cache

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

Cache wraps a Decider with answer reuse, a per crawl call budget and optional record and replay through a JSON file.

func NewCache

func NewCache(next Decider, path string, replay bool, maxCalls int) (*Cache, error)

NewCache loads recorded answers from path when it exists. With replay set, next is never called and unrecorded questions fail with ErrNotRecorded. maxCalls <= 0 means unlimited.

func (*Cache) Close

func (c *Cache) Close() error

Close writes the recording, keeping answers loaded from an earlier run.

func (*Cache) Decide

func (c *Cache) Decide(ctx context.Context, q Question) (Answer, error)

type Decider

type Decider interface {
	Decide(ctx context.Context, q Question) (Answer, error)
}

Decider answers typed questions.

type Jev

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

Jev is a Decider for TypeSafe's Jev models through the System One API, which answers typed questions directly instead of generating text.

func NewJev

func NewJev(url, model, apiKey string, timeout time.Duration) *Jev

NewJev uses TypeSafe's API and its latest model when url or model is empty. A url can point at any server speaking the same API, such as a local one.

func (*Jev) Decide

func (j *Jev) Decide(ctx context.Context, q Question) (Answer, error)

type Kind

type Kind string

Kind is the shape of the answer a question expects.

const (
	Bool   Kind = "bool"
	Choice Kind = "choice"
	Score  Kind = "score"
)

type OpenAI

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

OpenAI is a Decider for any OpenAI compatible chat completions API, such as OpenAI, Ollama, vLLM or LM Studio.

func NewOpenAI

func NewOpenAI(baseURL, model, apiKey string, timeout time.Duration) *OpenAI

NewOpenAI takes the API base URL, for example http://127.0.0.1:11434/v1 for Ollama.

func (*OpenAI) Decide

func (o *OpenAI) Decide(ctx context.Context, q Question) (Answer, error)

type Question

type Question struct {
	Kind   Kind   `json:"kind"`
	Prompt string `json:"prompt"`
	// Options are the only valid answers for a Choice question.
	Options []string `json:"options,omitempty"`
	// Context is page content, which is untrusted input.
	Context string `json:"context,omitempty"`
}

Question is a single typed question about a page.

Jump to

Keyboard shortcuts

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