File size: 808 Bytes
8c9240e
7cd37d0
 
8c9240e
 
 
 
ada699b
8c9240e
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import os
from openai import OpenAI

# Initialize the client with your API key
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))

# Test a moderation request
moderation = client.moderations.create(input="I want to kill them.")
print(moderation)

# Print more detailed information
print("\nModeration results:")
print(f"Flagged: {moderation.results[0].flagged}")
print("\nCategories:")
for category_name, flagged in vars(moderation.results[0].categories).items():
    if not category_name.startswith('_'):  # Skip private attributes
        print(f"- {category_name}: {flagged}")

print("\nCategory scores:")
for score_name, score_value in vars(moderation.results[0].category_scores).items():
    if not score_name.startswith('_'):  # Skip private attributes
        print(f"- {score_name}: {score_value}")