LoslegenKostenlos loslegen

Requesting moderation

Aside from text and chat completion models, OpenAI provides models with other capabilities, including text moderation. OpenAI's text moderation model is designed for evaluating prompts and responses to determine if they violate OpenAI's usage policies, including inciting hate speech and promoting violence.

In this exercise, you'll test out OpenAI's moderation functionality on a sentence that may have been flagged as containing violent content using traditional word detection algorithms.

Diese Übung ist Teil des Kurses

Multi-Modal Systems with the OpenAI API

Kurs anzeigen

Anleitung zur Übung

  • Check if "My favorite book is To Kill a Mockingbird." violates OpenAI’s policies using the Moderations endpoint.
  • Print the category scores to see the results.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

client = OpenAI(api_key="")

# Create a request to the Moderation endpoint
response = client.____.____(
    ____="My favorite book is To Kill a Mockingbird."
)

# Print the category scores
print(response.results[0].____)
Code bearbeiten und ausführen