Table of Contents

Class ModerationsEndpoint

Namespace
OpenAI.Moderations
Assembly
OpenAI-DotNet.dll

The moderation endpoint is a tool you can use to check whether content complies with OpenAI's content policy. Developers can thus identify content that our content policy prohibits and take action, for instance by filtering it.
https://platform.openai.com/docs/api-reference/moderations

public sealed class ModerationsEndpoint : OpenAIBaseEndpoint
Inheritance
ModerationsEndpoint
Inherited Members

Constructors

ModerationsEndpoint(OpenAIClient)

public ModerationsEndpoint(OpenAIClient client)

Parameters

client OpenAIClient

Properties

Root

The root endpoint address.

protected override string Root { get; }

Property Value

string

Methods

CreateModerationAsync(ModerationsRequest, CancellationToken)

Classifies if text violates OpenAI's Content Policy

public Task<ModerationsResponse> CreateModerationAsync(ModerationsRequest request, CancellationToken cancellationToken = default)

Parameters

request ModerationsRequest

ModerationsRequest.

cancellationToken CancellationToken

Optional, CancellationToken.

Returns

Task<ModerationsResponse>

GetModerationAsync(string, string, CancellationToken)

Classifies if text violates OpenAI's Content Policy.

public Task<bool> GetModerationAsync(string input, string model = null, CancellationToken cancellationToken = default)

Parameters

input string

The input text to classify.

model string

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.

cancellationToken CancellationToken

Optional, CancellationToken.

Returns

Task<bool>

True, if the text has been flagged by the model as violating OpenAI's content policy.

GetModerationChunkedAsync(string, string, int, int, CancellationToken)

Classifies if text violates OpenAI's Content Policy.

public Task<bool> GetModerationChunkedAsync(string input, string model = null, int chunkSize = 1000, int chunkOverlap = 100, CancellationToken cancellationToken = default)

Parameters

input string

The input text to classify.

model string

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.

chunkSize int

Maximum size each chunk can be.

chunkOverlap int

How many characters a chunk should contain from the previous chunk.

cancellationToken CancellationToken

Optional, CancellationToken.

Returns

Task<bool>

True, if the text has been flagged by the model as violating OpenAI's content policy.

Remarks

This version splits input into chunks and makes multiple moderation requests, which should provide better results when dealing with a large input.

On the first flagged chunk, the method returns.