DecisionModel

fun interface DecisionModel

A model that decides instead of writing: it picks one of the options you give it, answers yes or no, or rates something on a scale, and says how sure it is. Such a model is fast and cheap, and its answer has a fixed type, which makes it a good fit for the places where a graph has to decide: which node comes next, whether an answer is good enough, whether a person has to look.

Use ChatDecisionModel to decide with a chat model you already have, an implementation from an integration module (telar-typesafe for Jev), or write one. In a test, a lambda is enough:

val model = DecisionModel { request ->
DecisionResponse(request.questions.mapValues { Answer.YesNo(1.0) })
}

One request can ask several questions about the same DecisionRequest.state. For a single question, choose, isYes and score are shorter.

Inheritors

Functions

Link copied to clipboard
inline suspend fun <Option : Enum<Option>> DecisionModel.choose(state: String, instructions: String, describe: (Option) -> String? = { null }): Answer.Choice

Asks which constant of the enum Option fits state. The model sees the names of the constants, and for each one the text that describe returns. Read the constant from the answer with value.

suspend fun DecisionModel.choose(state: String, instructions: String, options: Map<String, String?>): Answer.Choice

Asks which of options fits state, for a node or an edge with one decision to make.

Link copied to clipboard
abstract suspend fun decide(request: DecisionRequest): DecisionResponse

Returns an answer for each question of request, under the name the question has there.

Link copied to clipboard
suspend fun DecisionModel.isYes(state: String, instructions: String): Answer.YesNo

Asks a yes/no question about state. Read Answer.YesNo.isYes, or compare Answer.YesNo.probability with a line of your own.

Link copied to clipboard
suspend fun DecisionModel.score(state: String, instructions: String, levels: List<String>): Answer.Score

Asks for a rating of state on the scale of levels, described from the lowest to the highest.