Class DecisionModelJudge
java.lang.Object
dev.langchain4j.test.judge.DecisionModelJudge
- All Implemented Interfaces:
Judge
A
Judge backed by a DecisionModel. Each criterion is asked as a yes/no question, and is satisfied
when the probability of "yes" is at least the threshold, 0.5 by default. Unless the criterion defines when it
passes and fails, the question tells the model to answer "no" when the criterion is satisfied only partly or when
it is unclear, so a passing criterion means the model considers it clearly satisfied. All criteria of an assertion
are asked in a single request; whether the answer to one criterion can be influenced by the others depends on the
decision model. So does how closely the model follows the pass and fail definitions of a JudgeCriterion: check
a few known cases before relying on them.
Created by Judge.from(DecisionModel).
A conversation given with JudgedTextAssert.given(List) is sent to the decision model as messages, with its
images and other media: an image whose detail level was not chosen when it was created (see
ImageContent.detailLevelSpecified()) is sent with
ImageContent.DetailLevel.AUTO, an image with a chosen detail level is sent as it is, the same way as by a
ChatModelJudge. An image read back from JSON, for example from a persistent chat memory store, counts as
having a chosen detail level, so it keeps ImageContent.DetailLevel.LOW.
-
Method Summary
Modifier and TypeMethodDescriptionevaluate(JudgeRequest judgeRequest) Judges the text of the request against each criterion, without failing.withQuestion(Function<JudgeCriterion, YesNoQuestion> questions) Returns a judge that asks each criterion with the question returned by the given function, instead of the default question.withThreshold(double threshold) Returns a judge with the given threshold: a criterion is satisfied when the probability of "yes" is greater than or equal to it.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Judge
assertThat
-
Method Details
-
withThreshold
Returns a judge with the given threshold: a criterion is satisfied when the probability of "yes" is greater than or equal to it.- Parameters:
threshold- greater than 0 and at most 1.
-
withQuestion
Returns a judge that asks each criterion with the question returned by the given function, instead of the default question. The decision model receives the text to judge asresponse, and, if given, the user message asuserMessageand the sources assources: the question can refer to them by these names. When a conversation is given (seeJudgedTextAssert.given(List)), the decision model instead receives the conversation followed by the text to judge as the last assistant message, so the question should refer to "the last assistant message". For example:
A judge can be created once and shared by all tests, for example in a constant or a test configuration. The default question was chosen by measuring how often judges give wrong verdicts with it. Check your question on a few cases with known verdicts before relying on it.DecisionModelJudge judge = Judge.from(decisionModel).withQuestion(criterion -> YesNoQuestion.builder() .text("Would a support agent accept this response? It must: " + criterion.text()) .yesWhen(criterion.satisfiedWhen() != null ? criterion.satisfiedWhen() : "it clearly does") .noWhen(criterion.notSatisfiedWhen() != null ? criterion.notSatisfiedWhen() : "it does not, or only partly") .build());- Parameters:
questions- returns the question to ask for a criterion
-
evaluate
Description copied from interface:JudgeJudges the text of the request against each criterion, without failing.
-