StubDecisionService

A decision service for tests that returns scripted outcomes and records each call.

Outcomes for ask, rate and question assess calls are scripted by question name, and outcomes for assess calls with a PropositionRequest by proposition text. classify returns the choice scripted for the request's question name, and otherwise the classification scripted for its set of category ids. A call with no scripted outcome throws IllegalStateException.

By default the stub answers a whole request in one question-set call. Question-set answers pass through the same question validation as provider answers, so a scripted choice outside its question's options, or rating evidence outside its levels, throws IllegalStateException from ask. A stub built after Builder.perQuestion answers each question on its own: a choice question through classify, and the other kinds through their per-question hooks. The stub accepts every question kind unless other capabilities are set.

val stub = StubDecisionService.builder("triage-stub")
.proposition("is_urgent", PropositionResult.Answered(true, provenance))
.build()

Types

Link copied to clipboard
@ApiStatus.Experimental
class Builder

Collects scripted outcomes for a StubDecisionService. Get one from StubDecisionService.builder. A later outcome for the same key replaces the earlier one.

Link copied to clipboard
object Companion

Creates stub decision services.

Properties

Link copied to clipboard
open override val name: String

Name of the LLM, such as "gpt-3.5-turbo"

Link copied to clipboard
open override val provider: String

Name of the provider, such as "OpenAI"

Link copied to clipboard
open override val type: ModelType

Family remains DECISION even when this service is used only for classification.

Functions

Link copied to clipboard

Answers a request.

open fun ask(input: String, spec: DecisionSpec): DecisionResponse

Answers the questions of a spec against the given input. It behaves as ask with a request.

Link copied to clipboard
open override fun assess(request: PropositionRequest): PropositionResult

Assess the proposition; a false answer is successful evidence, not an operational failure.

open override fun assess(input: String, question: PropositionQuestionSpec): PropositionResult

Answers one proposition question in its own provider call.

Link copied to clipboard
fun calls(): List<String>

Returns the names of the operations called so far, in call order: askQuestionSet, assess, classify and rate. A question assess call is recorded as assess.

Link copied to clipboard
open override fun capabilities(): DecisionCapabilities

Returns what this service can accept.

Link copied to clipboard

Classifies text with a spec. Same as calling classify with ClassificationRequest.of(input, spec).

Classify text using only the request's category domain, returning evidence rather than routing policy.

Link copied to clipboard
open fun infoString(verbose: Boolean?, indent: Int): String
Link copied to clipboard
open override fun metadata(): DecisionServiceMetadata

Pure DECISION metadata snapshot; never serialize a live service in place of this value.

Link copied to clipboard
open override fun rate(input: String, question: RatingQuestionSpec): RatingResult

Rates the input against one rating question in its own provider call. The caller validates the outcome against the question's levels.

Link copied to clipboard
open override fun toString(): String