Skip to content

Commit dcfabb6

Browse files
feat(api): api update
1 parent d5a07de commit dcfabb6

6 files changed

Lines changed: 66 additions & 6 deletions

File tree

‎.stats.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 27
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/moderation-api/moderation-api-cbf656f40e43acf60d9596f78204f031dc8c7205626df8f05ce8e88bcf49b597.yml
3-
openapi_spec_hash: 23be5a56248a1a575b34833eb7e7fe49
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/moderation-api/moderation-api-9c5291067ec36cba0c9ef772c5c8eb10238fb332f1f25d0e31f3f2ad87c24e5e.yml
3+
openapi_spec_hash: 790cc0a36d6ed693c06a285c441ab977
44
config_hash: 9d144cc6c49d3fd53e5b4472c1e22165

‎README.md‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,14 @@ from moderation_api import ModerationAPI
130130

131131
client = ModerationAPI()
132132

133-
author = client.authors.create(
134-
external_id="external_id",
135-
metadata={},
133+
response = client.content.submit(
134+
content={
135+
"text": "text",
136+
"type": "text",
137+
},
138+
client_action={"action": "review"},
136139
)
137-
print(author.metadata)
140+
print(response.client_action)
138141
```
139142

140143
## Handling errors

‎src/moderation_api/resources/content.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def submit(
5050
content: content_submit_params.Content,
5151
author_id: str | Omit = omit,
5252
channel: str | Omit = omit,
53+
client_action: content_submit_params.ClientAction | Omit = omit,
5354
content_id: str | Omit = omit,
5455
conversation_id: str | Omit = omit,
5556
do_not_store: bool | Omit = omit,
@@ -74,6 +75,10 @@ def submit(
7475
channel: Provide a channel ID or key. Will use the project's default channel if not
7576
provided.
7677
78+
client_action: A recommendation from your own client-side flagging (e.g. a banned-IP list or a
79+
third-party tool). Feeds the rules engine and can escalate or override the
80+
recommended action. Does not change whether our analysis flagged the content.
81+
7782
content_id: The unique ID of the content in your database.
7883
7984
conversation_id: For example the ID of a chat room or a post
@@ -104,6 +109,7 @@ def submit(
104109
"content": content,
105110
"author_id": author_id,
106111
"channel": channel,
112+
"client_action": client_action,
107113
"content_id": content_id,
108114
"conversation_id": conversation_id,
109115
"do_not_store": do_not_store,
@@ -147,6 +153,7 @@ async def submit(
147153
content: content_submit_params.Content,
148154
author_id: str | Omit = omit,
149155
channel: str | Omit = omit,
156+
client_action: content_submit_params.ClientAction | Omit = omit,
150157
content_id: str | Omit = omit,
151158
conversation_id: str | Omit = omit,
152159
do_not_store: bool | Omit = omit,
@@ -171,6 +178,10 @@ async def submit(
171178
channel: Provide a channel ID or key. Will use the project's default channel if not
172179
provided.
173180
181+
client_action: A recommendation from your own client-side flagging (e.g. a banned-IP list or a
182+
third-party tool). Feeds the rules engine and can escalate or override the
183+
recommended action. Does not change whether our analysis flagged the content.
184+
174185
content_id: The unique ID of the content in your database.
175186
176187
conversation_id: For example the ID of a chat room or a post
@@ -201,6 +212,7 @@ async def submit(
201212
"content": content,
202213
"author_id": author_id,
203214
"channel": channel,
215+
"client_action": client_action,
204216
"content_id": content_id,
205217
"conversation_id": conversation_id,
206218
"do_not_store": do_not_store,

‎src/moderation_api/types/content_submit_params.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"ContentObjectDataImage",
2222
"ContentObjectDataVideo",
2323
"ContentObjectDataAudio",
24+
"ClientAction",
2425
"Policy",
2526
"PolicyToxicity",
2627
"PolicyPersonalInformation",
@@ -69,6 +70,14 @@ class ContentSubmitParams(TypedDict, total=False):
6970
Will use the project's default channel if not provided.
7071
"""
7172

73+
client_action: Annotated[ClientAction, PropertyInfo(alias="clientAction")]
74+
"""A recommendation from your own client-side flagging (e.g.
75+
76+
a banned-IP list or a third-party tool). Feeds the rules engine and can escalate
77+
or override the recommended action. Does not change whether our analysis flagged
78+
the content.
79+
"""
80+
7281
content_id: Annotated[str, PropertyInfo(alias="contentId")]
7382
"""The unique ID of the content in your database."""
7483

@@ -200,6 +209,29 @@ class ContentObject(TypedDict, total=False):
200209
Content: TypeAlias = Union[ContentText, ContentImage, ContentVideo, ContentAudio, ContentObject]
201210

202211

212+
class ClientAction(TypedDict, total=False):
213+
"""A recommendation from your own client-side flagging (e.g.
214+
215+
a banned-IP list or a third-party tool). Feeds the rules engine and can escalate or override the recommended action. Does not change whether our analysis flagged the content.
216+
"""
217+
218+
action: Required[Literal["review", "allow", "reject"]]
219+
"""Your recommendation for the content: allow, review, or reject."""
220+
221+
behavior: Literal["override", "escalate"]
222+
"""How your recommendation combines with ours.
223+
224+
Defaults to 'escalate', which only applies it when stricter than ours;
225+
'override' replaces ours outright.
226+
"""
227+
228+
reason: str
229+
"""A human-readable explanation for your recommendation."""
230+
231+
source: str
232+
"""Where your recommendation came from, e.g. "banned-ip"."""
233+
234+
203235
class PolicyToxicity(TypedDict, total=False):
204236
id: Required[Literal["toxicity"]]
205237

‎src/moderation_api/types/content_submit_response.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ class Recommendation(BaseModel):
351351
"rule_match",
352352
"rule_default",
353353
"rule_fallback",
354+
"client_override",
354355
]
355356
]
356357
"""The reason code for the recommendation.

‎tests/api_resources/test_content.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ def test_method_submit_with_all_params(self, client: ModerationAPI) -> None:
3838
},
3939
author_id="authorId",
4040
channel="channel",
41+
client_action={
42+
"action": "review",
43+
"behavior": "override",
44+
"reason": "reason",
45+
"source": "source",
46+
},
4147
content_id="contentId",
4248
conversation_id="conversationId",
4349
do_not_store=True,
@@ -113,6 +119,12 @@ async def test_method_submit_with_all_params(self, async_client: AsyncModeration
113119
},
114120
author_id="authorId",
115121
channel="channel",
122+
client_action={
123+
"action": "review",
124+
"behavior": "override",
125+
"reason": "reason",
126+
"source": "source",
127+
},
116128
content_id="contentId",
117129
conversation_id="conversationId",
118130
do_not_store=True,

0 commit comments

Comments
 (0)