Skip to content

Commit 43464dc

Browse files
feat(api): add omni-moderation model (#1100)
1 parent b7db4b1 commit 43464dc

File tree

6 files changed

+174
-14
lines changed

6 files changed

+174
-14
lines changed

Diff for: .stats.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
configured_endpoints: 68
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-073331021d48db6af646a3552ab0c682efe31b7fb4e59a109ed1ba539f9b89c5.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-17ddd746c775ca4d4fbe64e5621ac30756ef09c061ff6313190b6ec162222d4c.yml

Diff for: api.md

+3
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,10 @@ Methods:
145145
Types:
146146

147147
- <code><a href="./src/resources/moderations.ts">Moderation</a></code>
148+
- <code><a href="./src/resources/moderations.ts">ModerationImageURLInput</a></code>
148149
- <code><a href="./src/resources/moderations.ts">ModerationModel</a></code>
150+
- <code><a href="./src/resources/moderations.ts">ModerationMultiModalInput</a></code>
151+
- <code><a href="./src/resources/moderations.ts">ModerationTextInput</a></code>
149152
- <code><a href="./src/resources/moderations.ts">ModerationCreateResponse</a></code>
150153

151154
Methods:

Diff for: src/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,10 @@ export namespace OpenAI {
302302

303303
export import Moderations = API.Moderations;
304304
export import Moderation = API.Moderation;
305+
export import ModerationImageURLInput = API.ModerationImageURLInput;
305306
export import ModerationModel = API.ModerationModel;
307+
export import ModerationMultiModalInput = API.ModerationMultiModalInput;
308+
export import ModerationTextInput = API.ModerationTextInput;
306309
export import ModerationCreateResponse = API.ModerationCreateResponse;
307310
export import ModerationCreateParams = API.ModerationCreateParams;
308311

Diff for: src/resources/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ export {
5252
export { Model, ModelDeleted, ModelsPage, Models } from './models';
5353
export {
5454
Moderation,
55+
ModerationImageURLInput,
5556
ModerationModel,
57+
ModerationMultiModalInput,
58+
ModerationTextInput,
5659
ModerationCreateResponse,
5760
ModerationCreateParams,
5861
Moderations,

Diff for: src/resources/moderations.ts

+163-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import * as ModerationsAPI from './moderations';
66

77
export class Moderations extends APIResource {
88
/**
9-
* Classifies if text is potentially harmful.
9+
* Classifies if text and/or image inputs are potentially harmful. Learn more in
10+
* the [moderation guide](https://platform.openai.com/docs/guides/moderation).
1011
*/
1112
create(
1213
body: ModerationCreateParams,
@@ -22,6 +23,11 @@ export interface Moderation {
2223
*/
2324
categories: Moderation.Categories;
2425

26+
/**
27+
* A list of the categories along with the input type(s) that the score applies to.
28+
*/
29+
category_applied_input_types: Moderation.CategoryAppliedInputTypes;
30+
2531
/**
2632
* A list of the categories along with their scores as predicted by model.
2733
*/
@@ -65,6 +71,20 @@ export namespace Moderation {
6571
*/
6672
'hate/threatening': boolean;
6773

74+
/**
75+
* Content that includes instructions or advice that facilitate the planning or
76+
* execution of wrongdoing, or that gives advice or instruction on how to commit
77+
* illicit acts. For example, "how to shoplift" would fit this category.
78+
*/
79+
illicit: boolean;
80+
81+
/**
82+
* Content that includes instructions or advice that facilitate the planning or
83+
* execution of wrongdoing that also includes violence, or that gives advice or
84+
* instruction on the procurement of any weapon.
85+
*/
86+
'illicit/violent': boolean;
87+
6888
/**
6989
* Content that promotes, encourages, or depicts acts of self-harm, such as
7090
* suicide, cutting, and eating disorders.
@@ -107,6 +127,76 @@ export namespace Moderation {
107127
'violence/graphic': boolean;
108128
}
109129

130+
/**
131+
* A list of the categories along with the input type(s) that the score applies to.
132+
*/
133+
export interface CategoryAppliedInputTypes {
134+
/**
135+
* The applied input type(s) for the category 'harassment'.
136+
*/
137+
harassment: Array<'text'>;
138+
139+
/**
140+
* The applied input type(s) for the category 'harassment/threatening'.
141+
*/
142+
'harassment/threatening': Array<'text'>;
143+
144+
/**
145+
* The applied input type(s) for the category 'hate'.
146+
*/
147+
hate: Array<'text'>;
148+
149+
/**
150+
* The applied input type(s) for the category 'hate/threatening'.
151+
*/
152+
'hate/threatening': Array<'text'>;
153+
154+
/**
155+
* The applied input type(s) for the category 'illicit'.
156+
*/
157+
illicit: Array<'text'>;
158+
159+
/**
160+
* The applied input type(s) for the category 'illicit/violent'.
161+
*/
162+
'illicit/violent': Array<'text'>;
163+
164+
/**
165+
* The applied input type(s) for the category 'self-harm'.
166+
*/
167+
'self-harm': Array<'text' | 'image'>;
168+
169+
/**
170+
* The applied input type(s) for the category 'self-harm/instructions'.
171+
*/
172+
'self-harm/instructions': Array<'text' | 'image'>;
173+
174+
/**
175+
* The applied input type(s) for the category 'self-harm/intent'.
176+
*/
177+
'self-harm/intent': Array<'text' | 'image'>;
178+
179+
/**
180+
* The applied input type(s) for the category 'sexual'.
181+
*/
182+
sexual: Array<'text' | 'image'>;
183+
184+
/**
185+
* The applied input type(s) for the category 'sexual/minors'.
186+
*/
187+
'sexual/minors': Array<'text'>;
188+
189+
/**
190+
* The applied input type(s) for the category 'violence'.
191+
*/
192+
violence: Array<'text' | 'image'>;
193+
194+
/**
195+
* The applied input type(s) for the category 'violence/graphic'.
196+
*/
197+
'violence/graphic': Array<'text' | 'image'>;
198+
}
199+
110200
/**
111201
* A list of the categories along with their scores as predicted by model.
112202
*/
@@ -131,6 +221,16 @@ export namespace Moderation {
131221
*/
132222
'hate/threatening': number;
133223

224+
/**
225+
* The score for the category 'illicit'.
226+
*/
227+
illicit: number;
228+
229+
/**
230+
* The score for the category 'illicit/violent'.
231+
*/
232+
'illicit/violent': number;
233+
134234
/**
135235
* The score for the category 'self-harm'.
136236
*/
@@ -168,7 +268,58 @@ export namespace Moderation {
168268
}
169269
}
170270

171-
export type ModerationModel = 'text-moderation-latest' | 'text-moderation-stable';
271+
/**
272+
* An object describing an image to classify.
273+
*/
274+
export interface ModerationImageURLInput {
275+
/**
276+
* Contains either an image URL or a data URL for a base64 encoded image.
277+
*/
278+
image_url: ModerationImageURLInput.ImageURL;
279+
280+
/**
281+
* Always `image_url`.
282+
*/
283+
type: 'image_url';
284+
}
285+
286+
export namespace ModerationImageURLInput {
287+
/**
288+
* Contains either an image URL or a data URL for a base64 encoded image.
289+
*/
290+
export interface ImageURL {
291+
/**
292+
* Either a URL of the image or the base64 encoded image data.
293+
*/
294+
url: string;
295+
}
296+
}
297+
298+
export type ModerationModel =
299+
| 'omni-moderation-latest'
300+
| 'omni-moderation-2024-09-26'
301+
| 'text-moderation-latest'
302+
| 'text-moderation-stable';
303+
304+
/**
305+
* An object describing an image to classify.
306+
*/
307+
export type ModerationMultiModalInput = ModerationImageURLInput | ModerationTextInput;
308+
309+
/**
310+
* An object describing text to classify.
311+
*/
312+
export interface ModerationTextInput {
313+
/**
314+
* A string of text to classify.
315+
*/
316+
text: string;
317+
318+
/**
319+
* Always `text`.
320+
*/
321+
type: 'text';
322+
}
172323

173324
/**
174325
* Represents if a given text input is potentially harmful.
@@ -192,26 +343,26 @@ export interface ModerationCreateResponse {
192343

193344
export interface ModerationCreateParams {
194345
/**
195-
* The input text to classify
346+
* Input (or inputs) to classify. Can be a single string, an array of strings, or
347+
* an array of multi-modal input objects similar to other models.
196348
*/
197-
input: string | Array<string>;
349+
input: string | Array<string> | Array<ModerationMultiModalInput>;
198350

199351
/**
200-
* Two content moderations models are available: `text-moderation-stable` and
201-
* `text-moderation-latest`.
202-
*
203-
* The default is `text-moderation-latest` which will be automatically upgraded
204-
* over time. This ensures you are always using our most accurate model. If you use
205-
* `text-moderation-stable`, we will provide advanced notice before updating the
206-
* model. Accuracy of `text-moderation-stable` may be slightly lower than for
207-
* `text-moderation-latest`.
352+
* The content moderation model you would like to use. Learn more in
353+
* [the moderation guide](https://platform.openai.com/docs/guides/moderation), and
354+
* learn about available models
355+
* [here](https://platform.openai.com/docs/models/moderation).
208356
*/
209357
model?: (string & {}) | ModerationModel;
210358
}
211359

212360
export namespace Moderations {
213361
export import Moderation = ModerationsAPI.Moderation;
362+
export import ModerationImageURLInput = ModerationsAPI.ModerationImageURLInput;
214363
export import ModerationModel = ModerationsAPI.ModerationModel;
364+
export import ModerationMultiModalInput = ModerationsAPI.ModerationMultiModalInput;
365+
export import ModerationTextInput = ModerationsAPI.ModerationTextInput;
215366
export import ModerationCreateResponse = ModerationsAPI.ModerationCreateResponse;
216367
export import ModerationCreateParams = ModerationsAPI.ModerationCreateParams;
217368
}

Diff for: tests/api-resources/moderations.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('resource moderations', () => {
2323
test('create: required and optional params', async () => {
2424
const response = await client.moderations.create({
2525
input: 'I want to kill them.',
26-
model: 'text-moderation-stable',
26+
model: 'omni-moderation-2024-09-26',
2727
});
2828
});
2929
});

0 commit comments

Comments
 (0)