Spectre.Router.LLMClassifier (Spectre v0.3.0)

Copy Markdown View Source

One-label LLM fallback classifier for Spectre routes.

Summary

Functions

Returns true when a classifier-specific or compatible main model is present.

Asks a configured LLM completion function to return exactly one label.

Returns true when LLM classification is enabled for the current router.

Renders visible labels as a flow-grouped taxonomy block.

Functions

available?(opts)

@spec available?(keyword()) :: boolean()

Returns true when a classifier-specific or compatible main model is present.

classify(text, labels, opts \\ [])

@spec classify(String.t(), [atom()], keyword()) ::
  {:ok, Spectre.Route.t()} | {:error, term()}

Asks a configured LLM completion function to return exactly one label.

enabled?(opts)

@spec enabled?(keyword()) :: boolean()

Returns true when LLM classification is enabled for the current router.

:llm_classifier? is an explicit override for custom pipelines. Otherwise the strategy must be present in the router's :via list. Merely configuring a main response model does not opt an agent into LLM routing.

label_tree(labels, rules, opts \\ [])

@spec label_tree([atom()], [Spectre.Rule.t() | map()], keyword()) :: String.t()

Renders visible labels as a flow-grouped taxonomy block.

Labels declared inside flows are grouped under their flow_path, one flow header per line ending with /, nested flows indented below their parent. Labels without a flow stay at the root level. When no visible rule declares a flow the output is the plain flat label list, one label per line.

Each label carries up to :examples (default 2) example phrases taken from the rule's embedding:, bag:, and jaro: declarations, rendered as LABEL — e.g. "phrase"; "phrase". Pass examples: 0 to disable.

tree = Spectre.Router.LLMClassifier.label_tree([:PAY_CARD], rules)