Hi everyone, I am trying to store the output of the moderation endpoint to analyze later. However, i can’t parse any of the info because the minute I save it in a pd dataframe or as a .csv file it turns into a string. The API documentation says that it should be a JSON output, but I do not seem to be getting that. When I try the following python code:
response = client.moderations.create(input="Sample text goes here.")
response.results[0]
I get the output:
Moderation(categories=Categories(harassment=False, harassment_threatening=False, hate=False, hate_threatening=False, self_minus_harm=False, self_minus_harm_instructions=False, self_minus_harm_intent=False, sexual=False, sexual_minors=False, violence=False, violence_graphic=False, self-harm=False, sexual/minors=False, hate/threatening=False, violence/graphic=False, self-harm/intent=False, self-harm/instructions=False, harassment/threatening=False), category_scores=CategoryScores(harassment=9.828779730014503e-05, harassment_threatening=7.383290494544781e-07, hate=2.796228727675043e-05, hate_threatening=8.01505279923731e-08, self_minus_harm=1.2543721084057324e-07, self_minus_harm_instructions=1.4000808290504096e-09, self_minus_harm_intent=7.407836477568708e-08, sexual=0.0029249193612486124, sexual_minors=6.004794613545528e-06, violence=8.165345207089558e-05, violence_graphic=5.865722414455377e-07, self-harm=1.2543721084057324e-07, sexual/minors=6.004794613545528e-06, hate/threatening=8.01505279923731e-08, violence/graphic=5.865722414455377e-07, self-harm/intent=7.407836477568708e-08, self-harm/instructions=1.4000808290504096e-09, harassment/threatening=7.383290494544781e-07), flagged=False)
This can’t be parsed into JSON using json.loads() or any other form because the Moderation object is not recognized. I am confused because the documentation says that the exact same code should produce the following output:
[
{
"flagged": true,
"categories": {
"sexual": false,
"hate": false,
"harassment": false,
"self-harm": false,
"sexual/minors": false,
"hate/threatening": false,
"violence/graphic": false,
"self-harm/intent": false,
"self-harm/instructions": false,
"harassment/threatening": true,
"violence": true,
},
"category_scores": {
"sexual": 1.2282071e-06,
"hate": 0.010696256,
"harassment": 0.29842457,
"self-harm": 1.5236925e-08,
"sexual/minors": 5.7246268e-08,
"hate/threatening": 0.0060676364,
"violence/graphic": 4.435014e-06,
"self-harm/intent": 8.098441e-10,
"self-harm/instructions": 2.8498655e-11,
"harassment/threatening": 0.63055265,
"violence": 0.99011886,
}
}
]
I’m not sure if I’m completely misinterpreting this, but I am really struggling to be able to store this on my machine and then open it up in another environment and be able to parse the object. Does anyone know about this? Thanks in advance!