Package dev.langchain4j.adaptiverag
Class HallucinationGrader
java.lang.Object
dev.langchain4j.adaptiverag.HallucinationGrader
- All Implemented Interfaces:
Function<HallucinationGrader.Arguments,
HallucinationGrader.Score>
public class HallucinationGrader
extends Object
implements Function<HallucinationGrader.Arguments,HallucinationGrader.Score>
Provides functionality to grade the groundedness of an LLM generation with respect to a set of facts.
The class implements the
Function
interface, which accepts parameters of type HallucinationGrader.Arguments
and returns a score indicating whether the generation is grounded or not.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Represents a set of facts and an associated LLM generation.static class
Binary score for hallucination present in generation answer. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionApplies the provided arguments to a chat language model and returns the score.
-
Constructor Details
-
HallucinationGrader
public HallucinationGrader()
-
-
Method Details
-
apply
Applies the provided arguments to a chat language model and returns the score. Uses OpenAI's GPT-3.5-Turbo model with specified settings. Logs requests and responses, retries twice, and has a max token limit of 2000.- Specified by:
apply
in interfaceFunction<HallucinationGrader.Arguments,
HallucinationGrader.Score> - Parameters:
args
- The arguments to be applied.- Returns:
- A Score object from the AI grader's invocation.
-