Skip to content
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: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 68
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-073331021d48db6af646a3552ab0c682efe31b7fb4e59a109ed1ba539f9b89c5.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-17ddd746c775ca4d4fbe64e5621ac30756ef09c061ff6313190b6ec162222d4c.yml
3 changes: 3 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ Methods:
Types:

- <code><a href="./src/resources/moderations.ts">Moderation</a></code>
- <code><a href="./src/resources/moderations.ts">ModerationImageURLInput</a></code>
- <code><a href="./src/resources/moderations.ts">ModerationModel</a></code>
- <code><a href="./src/resources/moderations.ts">ModerationMultiModalInput</a></code>
- <code><a href="./src/resources/moderations.ts">ModerationTextInput</a></code>
- <code><a href="./src/resources/moderations.ts">ModerationCreateResponse</a></code>

Methods:
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,10 @@ export namespace OpenAI {

export import Moderations = API.Moderations;
export import Moderation = API.Moderation;
export import ModerationImageURLInput = API.ModerationImageURLInput;
export import ModerationModel = API.ModerationModel;
export import ModerationMultiModalInput = API.ModerationMultiModalInput;
export import ModerationTextInput = API.ModerationTextInput;
export import ModerationCreateResponse = API.ModerationCreateResponse;
export import ModerationCreateParams = API.ModerationCreateParams;

Expand Down
3 changes: 3 additions & 0 deletions src/resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ export {
export { Model, ModelDeleted, ModelsPage, Models } from './models';
export {
Moderation,
ModerationImageURLInput,
ModerationModel,
ModerationMultiModalInput,
ModerationTextInput,
ModerationCreateResponse,
ModerationCreateParams,
Moderations,
Expand Down
175 changes: 163 additions & 12 deletions src/resources/moderations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import * as ModerationsAPI from './moderations';

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

/**
* A list of the categories along with the input type(s) that the score applies to.
*/
category_applied_input_types: Moderation.CategoryAppliedInputTypes;

/**
* A list of the categories along with their scores as predicted by model.
*/
Expand Down Expand Up @@ -65,6 +71,20 @@ export namespace Moderation {
*/
'hate/threatening': boolean;

/**
* Content that includes instructions or advice that facilitate the planning or
* execution of wrongdoing, or that gives advice or instruction on how to commit
* illicit acts. For example, "how to shoplift" would fit this category.
*/
illicit: boolean;

/**
* Content that includes instructions or advice that facilitate the planning or
* execution of wrongdoing that also includes violence, or that gives advice or
* instruction on the procurement of any weapon.
*/
'illicit/violent': boolean;

/**
* Content that promotes, encourages, or depicts acts of self-harm, such as
* suicide, cutting, and eating disorders.
Expand Down Expand Up @@ -107,6 +127,76 @@ export namespace Moderation {
'violence/graphic': boolean;
}

/**
* A list of the categories along with the input type(s) that the score applies to.
*/
export interface CategoryAppliedInputTypes {
/**
* The applied input type(s) for the category 'harassment'.
*/
harassment: Array<'text'>;

/**
* The applied input type(s) for the category 'harassment/threatening'.
*/
'harassment/threatening': Array<'text'>;

/**
* The applied input type(s) for the category 'hate'.
*/
hate: Array<'text'>;

/**
* The applied input type(s) for the category 'hate/threatening'.
*/
'hate/threatening': Array<'text'>;

/**
* The applied input type(s) for the category 'illicit'.
*/
illicit: Array<'text'>;

/**
* The applied input type(s) for the category 'illicit/violent'.
*/
'illicit/violent': Array<'text'>;

/**
* The applied input type(s) for the category 'self-harm'.
*/
'self-harm': Array<'text' | 'image'>;

/**
* The applied input type(s) for the category 'self-harm/instructions'.
*/
'self-harm/instructions': Array<'text' | 'image'>;

/**
* The applied input type(s) for the category 'self-harm/intent'.
*/
'self-harm/intent': Array<'text' | 'image'>;

/**
* The applied input type(s) for the category 'sexual'.
*/
sexual: Array<'text' | 'image'>;

/**
* The applied input type(s) for the category 'sexual/minors'.
*/
'sexual/minors': Array<'text'>;

/**
* The applied input type(s) for the category 'violence'.
*/
violence: Array<'text' | 'image'>;

/**
* The applied input type(s) for the category 'violence/graphic'.
*/
'violence/graphic': Array<'text' | 'image'>;
}

/**
* A list of the categories along with their scores as predicted by model.
*/
Expand All @@ -131,6 +221,16 @@ export namespace Moderation {
*/
'hate/threatening': number;

/**
* The score for the category 'illicit'.
*/
illicit: number;

/**
* The score for the category 'illicit/violent'.
*/
'illicit/violent': number;

/**
* The score for the category 'self-harm'.
*/
Expand Down Expand Up @@ -168,7 +268,58 @@ export namespace Moderation {
}
}

export type ModerationModel = 'text-moderation-latest' | 'text-moderation-stable';
/**
* An object describing an image to classify.
*/
export interface ModerationImageURLInput {
/**
* Contains either an image URL or a data URL for a base64 encoded image.
*/
image_url: ModerationImageURLInput.ImageURL;

/**
* Always `image_url`.
*/
type: 'image_url';
}

export namespace ModerationImageURLInput {
/**
* Contains either an image URL or a data URL for a base64 encoded image.
*/
export interface ImageURL {
/**
* Either a URL of the image or the base64 encoded image data.
*/
url: string;
}
}

export type ModerationModel =
| 'omni-moderation-latest'
| 'omni-moderation-2024-09-26'
| 'text-moderation-latest'
| 'text-moderation-stable';

/**
* An object describing an image to classify.
*/
export type ModerationMultiModalInput = ModerationImageURLInput | ModerationTextInput;

/**
* An object describing text to classify.
*/
export interface ModerationTextInput {
/**
* A string of text to classify.
*/
text: string;

/**
* Always `text`.
*/
type: 'text';
}

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

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

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

export namespace Moderations {
export import Moderation = ModerationsAPI.Moderation;
export import ModerationImageURLInput = ModerationsAPI.ModerationImageURLInput;
export import ModerationModel = ModerationsAPI.ModerationModel;
export import ModerationMultiModalInput = ModerationsAPI.ModerationMultiModalInput;
export import ModerationTextInput = ModerationsAPI.ModerationTextInput;
export import ModerationCreateResponse = ModerationsAPI.ModerationCreateResponse;
export import ModerationCreateParams = ModerationsAPI.ModerationCreateParams;
}
2 changes: 1 addition & 1 deletion tests/api-resources/moderations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('resource moderations', () => {
test('create: required and optional params', async () => {
const response = await client.moderations.create({
input: 'I want to kill them.',
model: 'text-moderation-stable',
model: 'omni-moderation-2024-09-26',
});
});
});