Package dev.langchain4j.adaptiverag
Record Class HallucinationGrader
java.lang.Object
java.lang.Record
dev.langchain4j.adaptiverag.HallucinationGrader
- All Implemented Interfaces:
Function<HallucinationGrader.Arguments,HallucinationGrader.Score>
public record HallucinationGrader(String openApiKey)
extends Record
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
Nested ClassesModifier and TypeClassDescriptionstatic final recordRepresents a set of facts and an associated LLM generation.static classBinary score for hallucination present in generation answer. -
Constructor Summary
ConstructorsConstructorDescriptionHallucinationGrader(String openApiKey) Creates an instance of aHallucinationGraderrecord class. -
Method Summary
Modifier and TypeMethodDescriptionApplies the provided arguments to a chat language model and returns the score.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.Returns the value of theopenApiKeyrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
HallucinationGrader
Creates an instance of aHallucinationGraderrecord class.- Parameters:
openApiKey- the value for theopenApiKeyrecord component
-
-
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:
applyin interfaceFunction<HallucinationGrader.Arguments,HallucinationGrader.Score> - Parameters:
args- The arguments to be applied.- Returns:
- A Score object from the AI grader's invocation.
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
openApiKey
Returns the value of theopenApiKeyrecord component.- Returns:
- the value of the
openApiKeyrecord component
-