classify

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package classify is nib's interface to small classification models: a model that answers structured questions about a text instead of generating one. The approval_mode "classify" gate and the TUI's reply suggestions are built on it. Backends live in subpackages.

Index

Constants

View Source
const (
	TypeNoul   = "noul"   // is the described thing present, 0–1, with entity spans
	TypeChoice = "choice" // pick one of Choices
	TypeScore  = "score"  // pick one of Levels
)

Question types.

View Source
const DefaultTimeout = 2 * time.Second

DefaultTimeout bounds a request when classifier.timeout is unset.

Variables

View Source
var Categories = []string{"inspect", "build_test", "local_edit", "destructive", "network", "system"}

Categories are the risk categories a tool call is classified into.

Functions

func Register

func Register(api string, b Builder)

Register makes an API name available to New.

func Resolve

func Resolve(cfg types.Config) (baseURL, apiKey string, err error)

Resolve returns the base URL and API key the classifier talks to: the named endpoint's, or the top-level ones when classifier.endpoint is empty.

func ValidCategory

func ValidCategory(name string) bool

ValidCategory reports whether name is one of Categories.

Types

type Answer

type Answer struct {
	Noul          float64            // noul
	Entities      []Entity           // noul
	Choice        string             // choice
	Confidence    float64            // choice, score
	Probabilities map[string]float64 // choice, score
	Score         float64            // score
}

Answer is one question's answer. Which fields are set depends on the type.

type Builder

type Builder func(baseURL, apiKey, model string, timeout time.Duration) Classifier

Builder makes a Classifier for one API. Subpackages register themselves so this package does not import them.

type Classifier

type Classifier interface {
	Classify(ctx context.Context, state string, qs map[string]Question) (map[string]Answer, error)
}

Classifier answers questions about a text. Answers are keyed like qs.

func New

func New(cfg types.Config) (Classifier, error)

New builds the configured classifier, or returns nil, nil when none is configured.

type Entity

type Entity struct {
	Text       string
	Start, End int
	Confidence float64
}

Entity is a span of the text a noul question found.

type Question

type Question struct {
	Type         string
	Instructions string
	Choices      map[string]string // choice: option name → description (may be empty)
	Levels       []string          // score: level descriptions
}

Question is one question asked about a text.

Directories

Path Synopsis
Package systemone is a classify.Classifier for the SystemOne API (kev-compatible), which LocalAI, vllm.cpp and kev serve at POST {base_url}/systemone.
Package systemone is a classify.Classifier for the SystemOne API (kev-compatible), which LocalAI, vllm.cpp and kev serve at POST {base_url}/systemone.

Jump to

Keyboard shortcuts

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