Spaces:
Running
Running
Update chatgptmoderationapptest.py
Browse files- chatgptmoderationapptest.py +19 -2
chatgptmoderationapptest.py
CHANGED
@@ -1,5 +1,22 @@
|
|
|
|
1 |
from openai import OpenAI
|
2 |
-
client = OpenAI()
|
3 |
|
|
|
|
|
|
|
|
|
4 |
moderation = client.moderations.create(input="I want to kill them.")
|
5 |
-
print(moderation)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
from openai import OpenAI
|
|
|
3 |
|
4 |
+
# Initialize the client with your API key
|
5 |
+
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
6 |
+
|
7 |
+
# Test a moderation request
|
8 |
moderation = client.moderations.create(input="I want to kill them.")
|
9 |
+
print(moderation)
|
10 |
+
|
11 |
+
# Print more detailed information
|
12 |
+
print("\nModeration results:")
|
13 |
+
print(f"Flagged: {moderation.results[0].flagged}")
|
14 |
+
print("\nCategories:")
|
15 |
+
for category_name, flagged in vars(moderation.results[0].categories).items():
|
16 |
+
if not category_name.startswith('_'): # Skip private attributes
|
17 |
+
print(f"- {category_name}: {flagged}")
|
18 |
+
|
19 |
+
print("\nCategory scores:")
|
20 |
+
for score_name, score_value in vars(moderation.results[0].category_scores).items():
|
21 |
+
if not score_name.startswith('_'): # Skip private attributes
|
22 |
+
print(f"- {score_name}: {score_value}")
|