
#  Requesting moderation

```
Exercise ID 1578142
```

##  Assignment 

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.

##  Pre exercise code 

```
import openai
```



##  Instructions 

- Assign your API key to `openai.api_key`.
- Create a request to the `Moderation` endpoint to determine if the text, `"My favorite book is How to Kill a Mockingbird."` violates OpenAI's usage policies.
- Print the category scores to see the results.



```
# Set your API key
openai.api_key = "____"

# Create a request to the Moderation endpoint
response = ____

# Print the category scores
print(____)
```

##  Hints 

- Create a request to the moderation endpoint using the `.create()` method on `openai.Moderation`.
- To use the latest moderation model, specify the `text-moderation-latest` model.



##  Solution 

```
# Set your API key
openai.api_key = "<OPENAI_API_TOKEN>"

# Create a request to the Moderation endpoint
response = openai.Moderation.create(
  model="text-moderation-latest",
  input="My favorite book is How to Kill a Mockingbird."
)

print(response["results"][0]["category_scores"])
```


