Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support both old & new structs for moderation.go #33

Closed
wants to merge 1 commit into from
Closed

Support both old & new structs for moderation.go #33

wants to merge 1 commit into from

Conversation

galpt
Copy link
Contributor

@galpt galpt commented Aug 3, 2022

This should fix the error:
json: cannot unmarshal number into Go struct field ResultCategories.results.categories.hate of type bool

Looking at this comment, it seems that OpenAI still haven't applied the new changes, and the previous pull request will cause the above json error.

I decided to include both the current moderation struct & the new struct that will likely be used in the near future.

@galpt galpt marked this pull request as ready for review August 3, 2022 12:24
@galpt
Copy link
Contributor Author

galpt commented Aug 4, 2022

Since it's starting tomorrow (Friday, August 5th 2022), I guess I would test it again tomorrow to see if anything breaks, and this pull request can wait until August 6th.
Might as well remove the old structs to make the code clean.

@galpt
Copy link
Contributor Author

galpt commented Aug 5, 2022

I'm closing this as the previous pull request should work just fine with the new Moderations endpoint changes.
An email about this:

Hi there,

Thanks for being a user of OpenAI’s Moderations endpoint. I’m following up to inform you that the following breaking change in our API is now live. The type of moderation endpoint response fields flagged and each field in categories have changed from Integer to Boolean. Return values that were 1 are now true and return values of 0 are now false. Below is an example output of the updated endpoint.

If your application relies on these fields being integers, please update your code to rely on booleans. Otherwise no action is required on your end.

Please reach out to support@openai.com if you have any concerns with this change. Thanks!

{
  "id": "modr-XXXXX",
  "model": "text-moderation-001",
  "results": [
    {
      "categories": {
        "hate": false,
        "hate/threatening": false,
        "self-harm": false,
        "sexual": false,
        "sexual/minors": false,
        "violence": false,
        "violence/graphic": false
      },
      "category_scores": {
        "hate": 0.18805529177188873,
        "hate/threatening": 0.0001250059431185946,
        "self-harm": 0.0003706029092427343,
        "sexual": 0.0008735615410842001,
        "sexual/minors": 0.0007470346172340214,
        "violence": 0.0041268812492489815,
        "violence/graphic": 0.00023186142789199948
      },
      "flagged": false
    }
  ]

Best,
Angela

@galpt galpt closed this Aug 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant