Use the moderations endpoint to identify content that may violate usage policies, such as text or images involving violence, hate speech, harassment, self-harm, or sexual content.You can use two models for this endpoint:
omni-moderation-latest: This model and all snapshots support more categorization options and multi-modal inputs.
text-moderation-latest(Legacy): Older model that supports only text inputs and fewer input categorizations. The newer omni-moderation models will be the best choice for new applications.
You can add these models in your OpenAI provider account.Code Snippets
from openai import OpenAIBASE_URL = "{GATEWAY_BASE_URL}"API_KEY = "your-truefoundry-api-key"# Configure OpenAI client with TrueFoundry settingsclient = OpenAI( api_key=API_KEY, base_url=BASE_URL,)response = client.moderations.create( model="openai-main/omni-moderation-latest", input=[ {"type": "text", "text": "Text to check for moderation"}, { "type": "image_url", "image_url": { "url": "https://example.com/image.png", } }, ],)print(response)
Here’s a full example output, where the input is an image from a single frame of a war movie. The model correctly predicts indicators of violence in the image, with a violence category score of greater than 0.8.