Class Choice<E>
java.lang.Object
dev.langchain4j.service.decision.Choice<E>
- Type Parameters:
E- the type of the options: an enum whose constants are the options, or for exampleString
The answer to a question of a decision service that chooses one of several options: the chosen option, the
probability of each option and, if the model reports one, a confidence. It is the typed counterpart of
ChoiceAnswer.
Decision services create it for enums, whose constants are the options. It can also be built for options that are
only known at runtime, such as strings, for example from a ChoiceAnswer of the DecisionModel API.
- Since:
- 1.21.0
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic <E> Choice.Builder<E> builder()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.The probability of each option.doubleprobabilityOf(E option) The probability of the given option, or 0 if the model reported probabilities but none for this option.toString()value()The chosen option, usually the one with the highest probability.
-
Method Details
-
builder
-
value
The chosen option, usually the one with the highest probability. -
probabilities
-
probabilityOf
The probability of the given option, or 0 if the model reported probabilities but none for this option.- Throws:
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
How confident the model is invalue(), from 0 to 1, ornullif the model does not report a confidence. The formula is defined by each model, so preferprobabilities()for thresholds. -
equals
-
hashCode
-
toString
-