Class DecisionResponse
java.lang.Object
dev.langchain4j.model.decision.response.DecisionResponse
The response of a
DecisionModel: one DecisionAnswer per question
of the request, keyed by question name, together with the DecisionResponseMetadata (model name, token
usage).
DecisionResponse response = decisionModel.decide(request);
ChoiceAnswer team = response.choice("team");
YesNoAnswer urgent = response.yesNo("urgent");
if (urgent.probability() > 0.8) {
escalate(team.value());
}
A question that the model refused to answer has a RefusalAnswer: check isRefused(String) before
reading its answer, since the typed accessors throw a ContentFilteredException for it.- Since:
- 1.21.0
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescription<A extends DecisionAnswer>
AReturns the answer with the given name, as the given answer type.answers()The answers, keyed by the names of the questions they answer.static DecisionResponse.Builderbuilder()Returns the answer to theChoiceQuestionwith the given name.booleaninthashCode()booleanWhether the model refused to answer the question with the given name, for example because the input or the question goes against the usage policies of the provider (seeRefusalAnswer).metadata()The name of the model that produced the answers, ornullif the model did not report it.Returns the answer to theScaleQuestionwith the given name.The token usage of the call, ornullif the model did not report it.toString()Returns the answer to theYesNoQuestionwith the given name.
-
Method Details
-
answers
The answers, keyed by the names of the questions they answer. The answer to a question that the model refused to answer is aRefusalAnswer. -
yesNo
Returns the answer to theYesNoQuestionwith the given name.- Throws:
IllegalArgumentException- if there is no answer with this name, or it is not aYesNoAnswer.ContentFilteredException- if the model refused to answer the question (seeisRefused(String)).
-
choice
Returns the answer to theChoiceQuestionwith the given name.- Throws:
IllegalArgumentException- if there is no answer with this name, or it is not aChoiceAnswer.ContentFilteredException- if the model refused to answer the question (seeisRefused(String)).
-
scale
Returns the answer to theScaleQuestionwith the given name.- Throws:
IllegalArgumentException- if there is no answer with this name, or it is not aScaleAnswer.ContentFilteredException- if the model refused to answer the question (seeisRefused(String)).
-
answer
Returns the answer with the given name, as the given answer type. Useful for answer types defined by integrations.- Throws:
IllegalArgumentException- if there is no answer with this name, or it is not of the given type.ContentFilteredException- if the model refused to answer the question (seeisRefused(String)) and the given type is neitherRefusalAnswernorDecisionAnswer.
-
isRefused
Whether the model refused to answer the question with the given name, for example because the input or the question goes against the usage policies of the provider (seeRefusalAnswer). When the decision is used as a safety check, treat a refused answer as a failed check rather than as a "no".- Throws:
IllegalArgumentException- if there is no answer with this name.- Since:
- 1.22.0
-
metadata
-
modelName
The name of the model that produced the answers, ornullif the model did not report it. -
tokenUsage
The token usage of the call, ornullif the model did not report it. -
builder
-
equals
-
hashCode
-
toString
-