Class ChoiceAnswer
java.lang.Object
dev.langchain4j.model.decision.response.ChoiceAnswer
- All Implemented Interfaces:
DecisionAnswer
The answer to a
ChoiceQuestion: the chosen option, the probability
of each option and, if the model reports one, a confidence.- Since:
- 1.21.0
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic ChoiceAnswer.Builderbuilder()How confident the model is invalue(), from 0 to 1, ornullif the model does not report a confidence.booleaninthashCode()doublemargin()The difference between the two highest probabilities, from 0 to 1.options()The names of the options that were offered, in the order of the question.The probability of each option, keyed by option name.doubleprobabilityOf(String option) The probability of the given option, or 0 if the model reported probabilities but none for this option.toString()value()The name of the chosen option, usually the one with the highest probability.
-
Method Details
-
value
The name of the chosen option, usually the one with the highest probability. -
probabilities
The probability of each option, keyed by option name. Empty if the model does not report probabilities.Unlike
confidence(), probabilities have the same meaning for every model, which makes them the better basis for thresholds. Their calibration still differs between models, so thresholds need to be tuned again when the model changes. -
options
The names of the options that were offered, in the order of the question.They are set by the
DecisionModelafter checking the answer against the question, so they are always present in aDecisionResponsereturned by a decision model. They are empty for an answer that was built without them. -
probabilityOf
The probability of the given option, or 0 if the model reported probabilities but none for this option.- Throws:
IllegalArgumentException- if the option was not offered (seeoptions()), for example because its name is misspelled.IllegalStateException- if the model did not report probabilities.
-
margin
public double margin()The difference between the two highest probabilities, from 0 to 1. A small margin means the model hesitated between two options, which is a common signal to escalate, for example to a human.If the model reported probabilities for only some of the options, the probability it did not report is assumed to belong to a single other option, so the margin is never overestimated.
- Throws:
IllegalStateException- if the model did not report probabilities.
-
confidence
-
builder
-
equals
-
hashCode
-
toString
-