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

V0.20.0: Add moderation endpoint (#134) #101

Merged
merged 2 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions openai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
File,
FineTune,
Model,
Moderation,
Search,
)
from openai.error import APIError, InvalidRequestError, OpenAIError
Expand Down Expand Up @@ -55,6 +56,7 @@
"FineTune",
"InvalidRequestError",
"Model",
"Moderation",
"OpenAIError",
"Search",
"api_base",
Expand Down
1 change: 1 addition & 0 deletions openai/api_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
from openai.api_resources.file import File # noqa: F401
from openai.api_resources.fine_tune import FineTune # noqa: F401
from openai.api_resources.model import Model # noqa: F401
from openai.api_resources.moderation import Moderation # noqa: F401
from openai.api_resources.search import Search # noqa: F401
22 changes: 22 additions & 0 deletions openai/api_resources/moderation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from typing import List, Optional, Union

from openai.openai_object import OpenAIObject


class Moderation(OpenAIObject):
VALID_MODEL_NAMES: List[str] = ["text-moderation-stable", "text-moderation-latest"]

@classmethod
def get_url(self):
return "/moderations"

@classmethod
def create(cls, input: Union[str, List[str]], model: Optional[str] = None):
if model not in cls.VALID_MODEL_NAMES:
raise ValueError(
f"The parameter model should be chosen from {cls.VALID_MODEL_NAMES} "
f"and it is default to be None."
)

instance = cls()
return instance.request("post", cls.get_url(), {"input": input, "model": model})
2 changes: 1 addition & 1 deletion openai/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "0.19.0"
VERSION = "0.20.0"