-
Notifications
You must be signed in to change notification settings - Fork 422
Expand file tree
/
Copy pathModerationEndpoint.cs
More file actions
51 lines (46 loc) · 1.98 KB
/
ModerationEndpoint.cs
File metadata and controls
51 lines (46 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using OpenAI_API.Models;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace OpenAI_API.Moderation
{
/// <summary>
/// This endpoint classifies text against the OpenAI Content Policy
/// </summary>
public class ModerationEndpoint : EndpointBase, IModerationEndpoint
{
/// <summary>
/// This allows you to send request to the recommended model without needing to specify. OpenAI recommends using the <see cref="Model.TextModerationLatest"/> model
/// </summary>
public ModerationRequest DefaultModerationRequestArgs { get; set; } = new ModerationRequest() { Model = Model.TextModerationLatest };
/// <summary>
/// The name of the endpoint, which is the final path segment in the API URL. For example, "completions".
/// </summary>
protected override string Endpoint { get { return "moderations"; } }
/// <summary>
/// Constructor of the api endpoint. Rather than instantiating this yourself, access it through an instance of <see cref="OpenAIAPI"/> as <see cref="OpenAIAPI.Moderation"/>.
/// </summary>
/// <param name="api"></param>
internal ModerationEndpoint(OpenAIAPI api) : base(api) { }
/// <summary>
/// Ask the API to classify the text using the default model.
/// </summary>
/// <param name="input">Text to classify</param>
/// <returns>Asynchronously returns the classification result</returns>
public async Task<ModerationResult> CallModerationAsync(string input)
{
ModerationRequest req = new ModerationRequest(DefaultModerationRequestArgs.Model, input);
return await CallModerationAsync(req);
}
/// <summary>
/// Ask the API to classify the text using a custom request.
/// </summary>
/// <param name="request">Request to send to the API</param>
/// <returns>Asynchronously returns the classification result</returns>
public async Task<ModerationResult> CallModerationAsync(ModerationRequest request)
{
return await HttpPostAsync<ModerationResult>(postData: request);
}
}
}