Skip to content

Commit 3852e25

Browse files
author
Lilian
authored
V0.20.0: Add moderation endpoint (#134) (#101)
* V0.19.1: Add moderation endpoint (#134) * Add moderation endpoint * Add version * version to model * s/version/model * fix formatting * model default to None * fix test * update value error message * version to 0.20.0
1 parent 64c4533 commit 3852e25

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

openai/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
File,
1919
FineTune,
2020
Model,
21+
Moderation,
2122
Search,
2223
)
2324
from openai.error import APIError, InvalidRequestError, OpenAIError
@@ -55,6 +56,7 @@
5556
"FineTune",
5657
"InvalidRequestError",
5758
"Model",
59+
"Moderation",
5860
"OpenAIError",
5961
"Search",
6062
"api_base",

openai/api_resources/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
from openai.api_resources.file import File # noqa: F401
1111
from openai.api_resources.fine_tune import FineTune # noqa: F401
1212
from openai.api_resources.model import Model # noqa: F401
13+
from openai.api_resources.moderation import Moderation # noqa: F401
1314
from openai.api_resources.search import Search # noqa: F401

openai/api_resources/moderation.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from typing import List, Optional, Union
2+
3+
from openai.openai_object import OpenAIObject
4+
5+
6+
class Moderation(OpenAIObject):
7+
VALID_MODEL_NAMES: List[str] = ["text-moderation-stable", "text-moderation-latest"]
8+
9+
@classmethod
10+
def get_url(self):
11+
return "/moderations"
12+
13+
@classmethod
14+
def create(cls, input: Union[str, List[str]], model: Optional[str] = None):
15+
if model not in cls.VALID_MODEL_NAMES:
16+
raise ValueError(
17+
f"The parameter model should be chosen from {cls.VALID_MODEL_NAMES} "
18+
f"and it is default to be None."
19+
)
20+
21+
instance = cls()
22+
return instance.request("post", cls.get_url(), {"input": input, "model": model})

openai/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = "0.19.0"
1+
VERSION = "0.20.0"

0 commit comments

Comments
 (0)