diff --git a/.stats.yml b/.stats.yml index e8bca3c6d..0998368a4 100644 --- a/.stats.yml +++ b/.stats.yml @@ -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 diff --git a/api.md b/api.md index 522de043c..5c3f552d8 100644 --- a/api.md +++ b/api.md @@ -144,7 +144,10 @@ Methods: Types: - Moderation +- ModerationImageURLInput - ModerationModel +- ModerationMultiModalInput +- ModerationTextInput - ModerationCreateResponse Methods: diff --git a/src/index.ts b/src/index.ts index ddb6c0833..4714b4ce4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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; diff --git a/src/resources/index.ts b/src/resources/index.ts index 87203ab39..15c5db77f 100644 --- a/src/resources/index.ts +++ b/src/resources/index.ts @@ -52,7 +52,10 @@ export { export { Model, ModelDeleted, ModelsPage, Models } from './models'; export { Moderation, + ModerationImageURLInput, ModerationModel, + ModerationMultiModalInput, + ModerationTextInput, ModerationCreateResponse, ModerationCreateParams, Moderations, diff --git a/src/resources/moderations.ts b/src/resources/moderations.ts index f80bc7acb..ba800509e 100644 --- a/src/resources/moderations.ts +++ b/src/resources/moderations.ts @@ -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, @@ -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. */ @@ -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. @@ -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. */ @@ -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'. */ @@ -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. @@ -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; + input: string | Array | Array; /** - * 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; } diff --git a/tests/api-resources/moderations.test.ts b/tests/api-resources/moderations.test.ts index 0df1f0371..64f9acf3c 100644 --- a/tests/api-resources/moderations.test.ts +++ b/tests/api-resources/moderations.test.ts @@ -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', }); }); });