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

Missing moderation categories #633

Open
richdawe-cio opened this issue Jan 8, 2024 · 3 comments
Open

Missing moderation categories #633

richdawe-cio opened this issue Jan 8, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@richdawe-cio
Copy link

Describe the bug

The moderations endpoint returns a number of categories that are not supported by go-openai. I'm not going to list them here, but the entire harrassment category is missing, along with some subcategories.

To Reproduce

Take a look at the categories listed by:

curl -H 'Authorization: Bearer API-KEY-GOES-HERE' -H 'Content-Type: application/json' -d '{ "input": "OHAI" }' https://api.openai.com/v1/moderations

and compare it with the list in https://github.com/sashabaranov/go-openai/blob/master/moderation.go

Expected behavior

I expect all moderation categories to be available in the openai.ResultCategories and openai.ResultCategoryScores structs.

Suggestion: Perhaps the moderation code could use map types, instead of having hard-coded fields. That way, the code would not have to change everytime OpenAI adds a new moderation type.

Screenshots/Logs
If applicable, add screenshots to help explain your problem. For non-graphical issues, please provide any relevant logs or stack traces.

Environment (please complete the following information):

  • go-openai version: v1.17.5
  • Go version: go1.20.11 darwin/arm64
  • OpenAI API version: latest (as of 2024-01-08)
  • OS: macOS Ventura

Additional context
Add any other context about the problem here.

@richdawe-cio richdawe-cio added the bug Something isn't working label Jan 8, 2024
@stillmatic
Copy link
Contributor

{
  "id": "modr-something",
  "model": "text-moderation-006",
  "results": [
    {
      "flagged": false,
      "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": false,
        "violence": false
      },
      "category_scores": {
        "sexual": 0.005986555479466915,
        "hate": 0.00019341870211064816,
        "harassment": 0.00013092363951727748,
        "self-harm": 1.1213144262001151e-6,
        "sexual/minors": 0.00009209589188685641,
        "hate/threatening": 3.4858462640841026e-6,
        "violence/graphic": 4.281196652300423e-6,
        "self-harm/intent": 8.618121114523092e-7,
        "self-harm/instructions": 1.192578224618046e-6,
        "harassment/threatening": 2.3499235339841107e-6,
        "violence": 0.000017707703591440804
      }
    }
  ]
}

guess they updated their moderation API. should be trivial PR if anyone wants to update those categories!

@richdawe-cio
Copy link
Author

I would be interested if anyone has any thoughts on my suggestion:

Perhaps the moderation code could use map types, instead of having hard-coded fields. That way, the code would not have to change everytime OpenAI adds a new moderation type.

@stillmatic
Copy link
Contributor

seems fair! compatibility on this endpoint seems to be 'best effort' from their side anyways, enforcing that callers be careful about ensuring that the field they want exists in the map is probably good practice, and means that there's less code maintenance required in the future here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants