Record Class GeminiSafetyRating
java.lang.Object
java.lang.Record
dev.langchain4j.model.googleai.GeminiSafetyRating
- Record Components:
category- the harm category being assessed, for example"HARM_CATEGORY_HARASSMENT"or"HARM_CATEGORY_DANGEROUS_CONTENT"probability- how likely the content is to belong to this category:"NEGLIGIBLE","LOW","MEDIUM"or"HIGH"blocked- whether this category caused the content to be blocked;nullwhen the API does not report it
public record GeminiSafetyRating(String category, String probability, Boolean blocked)
extends Record
A safety assessment that Gemini reports for a single harm category.
Gemini evaluates both the prompt you send and the content it generates against a set of harm categories,
and returns one rating per category. Ratings are available from
GoogleAiGeminiChatResponseMetadata.safetyRatings() (for the generated content) and
GoogleAiGeminiChatResponseMetadata.promptSafetyRatings() (for the prompt):
ChatResponse response = model.chat(ChatRequest.builder().messages(userMessage).build());
var metadata = (GoogleAiGeminiChatResponseMetadata) response.metadata();
for (GeminiSafetyRating rating : metadata.safetyRatings()) {
System.out.println(rating.category() + ": " + rating.probability());
}
category and probability are the raw values returned by the Gemini API rather than Java enums,
so that categories introduced by Google in the future are surfaced as-is instead of breaking response parsing.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionGeminiSafetyRating(String category, String probability, Boolean blocked) Creates an instance of aGeminiSafetyRatingrecord class. -
Method Summary
Modifier and TypeMethodDescriptionblocked()Returns the value of theblockedrecord component.category()Returns the value of thecategoryrecord component.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 theprobabilityrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
GeminiSafetyRating
Creates an instance of aGeminiSafetyRatingrecord class.- Parameters:
category- the value for thecategoryrecord componentprobability- the value for theprobabilityrecord componentblocked- the value for theblockedrecord component
-
-
Method Details
-
toString
-
hashCode
-
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). -
category
-
probability
Returns the value of theprobabilityrecord component.- Returns:
- the value of the
probabilityrecord component
-
blocked
-