choose

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.

val classify = node("classify", work = { email ->
model.choose(
email.body,
"Which team should handle this email?",
mapOf("refund" to "The customer wants money back", "technical" to "Something does not work"),
)
}) { email, answer -> email.copy(team = answer.option, sure = answer.confidence) }

Parameters

options

the options by name, each with a description of when it applies, or null.

Throws

when the call fails, or the model picks something that is not an option.


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.

enum class Team(val handles: String) { REFUND("The customer wants money back"), TECHNICAL("Something does not work") }

val team: Team = model.choose<Team>(email.body, "Which team should handle this email?") { it.handles }.value()

Throws

when the call fails, or the model picks something that is not a constant.