UNPKG

@juspay/neurolink

Version:

The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002

56 lines (55 loc) • 3.13 kB
/** * Classification strategies for the ClassifierRouter. * * - `classifyHeuristic` — zero-cost, no LLM. Generalizes the existing binary * task classifier scorer (fast vs reasoning) into five difficulty tiers. * - `classifyLlm` — runs a cheap "classifier model" via an injected generate * function, asking for a schema-constrained difficulty verdict. Falls back to * the heuristic on any failure. * - `classifyJev` — one round trip to a decision model, which answers * difficulty, capabilities, risk and model choice *simultaneously* and * reports a calibrated confidence. Falls back to the heuristic on any * failure or when the verdict is not confident enough to act on. */ import type { ClassifierCandidate, ClassifierContextScope, ClassifierDecideFn, ClassifierDecision, ClassifierDifficulty, ClassifierGenerateFn, ClassifierModelRef, ClassifierRouterInput } from "../types/index.js"; /** Difficulty tiers, ordered easiest → hardest. */ export declare const CLASSIFIER_DIFFICULTIES: ClassifierDifficulty[]; /** * Heuristic classifier — maps the binary fast/reasoning scores plus prompt * length into one of five difficulty tiers. Deterministic and dependency-free. */ export declare function classifyHeuristic(input: ClassifierRouterInput): ClassifierDecision; /** * LLM classifier — asks a cheap model for a schema-constrained verdict. * Falls back to the heuristic if the model is unavailable, times out, or * returns output that does not match the schema. */ export declare function classifyLlm(input: ClassifierRouterInput, generate: ClassifierGenerateFn, classifierModel?: ClassifierModelRef, timeoutMs?: number, candidates?: ClassifierCandidate[]): Promise<ClassifierDecision>; /** * How much context the request needs, narrowest → widest. Ordered, because a * decision model places things on a scale reliably and names numbers badly: * asking "how many tokens" would get digits read as text, while asking "which * of these four descriptions fits" gets a calibrated position. */ export declare const CLASSIFIER_CONTEXT_SCOPES: ClassifierContextScope[]; /** * Map a score answer onto a compaction threshold, clamped so it can only ever * lower the default. */ export declare function contextScopeToThreshold(index: number): number; /** * Decision-model classifier — one request answers difficulty, capabilities, * risk and model selection at once. * * Latency is flat in question count (1 question ~393ms, 400 ~465ms), so the * capability questions are effectively free and are asked speculatively even * when nothing downstream may need them. This is the opposite of the LLM * strategy's economics, where every extra field costs output tokens. * * Returns the heuristic verdict — never throws — when no decision provider is * configured, the call fails, or the answer is not confident enough to act on. */ export declare function classifyJev(input: ClassifierRouterInput, decide: ClassifierDecideFn, timeoutMs?: number, candidates?: ClassifierCandidate[], thresholds?: { upgrade?: number; downgrade?: number; }): Promise<ClassifierDecision>;