Interface ModerationModel
- All Known Implementing Classes:
DisabledModerationModel, MistralAiModerationModel, OpenAiModerationModel, WatsonxModerationModel
public interface ModerationModel
Represents a model that can moderate text.
-
Method Summary
Modifier and TypeMethodDescriptiondefault ModerationResponsedoModerate(ModerationRequest moderationRequest) Performs the actual moderation.default List<ModerationModelListener> Returns the list of listeners for this moderation model.default StringReturns the model name for this moderation model.default Response<Moderation> moderate(ChatMessage message) Moderates the given chat message.default Response<Moderation> moderate(TextSegment textSegment) Moderates the given text segment.default Response<Moderation> Moderates the given prompt.default ModerationResponsemoderate(ModerationRequest moderationRequest) This is the main API to interact with the moderation model.default Response<Moderation> Moderates the given text.default Response<Moderation> moderate(List<ChatMessage> messages) Moderates the given list of chat messages.default ModelProviderprovider()Returns the model provider for this moderation model.static StringtoText(ChatMessage chatMessage) Converts a ChatMessage to its text representation.
-
Method Details
-
moderate
This is the main API to interact with the moderation model.- Parameters:
moderationRequest- aModerationRequest, containing all the inputs to the moderation model- Returns:
- a
ModerationResponse, containing all the outputs from the moderation model
-
doModerate
Performs the actual moderation. This method should be overridden by implementations.- Parameters:
moderationRequest- the moderation request.- Returns:
- the moderation response.
-
moderate
Moderates the given text.- Parameters:
text- the text to moderate.- Returns:
- the moderation
Response.
-
moderate
Moderates the given prompt.- Parameters:
prompt- the prompt to moderate.- Returns:
- the moderation
Response.
-
moderate
Moderates the given chat message.- Parameters:
message- the chat message to moderate.- Returns:
- the moderation
Response.
-
moderate
Moderates the given list of chat messages.- Parameters:
messages- the list of chat messages to moderate.- Returns:
- the moderation
Response.
-
moderate
Moderates the given text segment.- Parameters:
textSegment- the text segment to moderate.- Returns:
- the moderation
Response.
-
toText
Converts a ChatMessage to its text representation. This is a helper method for implementations.- Parameters:
chatMessage- the chat message- Returns:
- the text content of the message
- Throws:
IllegalArgumentException- if the message type is unsupported
-
listeners
Returns the list of listeners for this moderation model.- Returns:
- the list of listeners, or an empty list if none are registered.
-
provider
Returns the model provider for this moderation model.- Returns:
- the model provider.
-
modelName
Returns the model name for this moderation model.- Returns:
- the model name, or
nullif not available.
-