go/resources/moderations/methods/create/index.md +0 −419 deleted
File Deleted View Diff
1## Create moderation
2
3`client.Moderations.New(ctx, body) (*ModerationNewResponse, error)`
4
5**post** `/moderations`
6
7Classifies if text and/or image inputs are potentially harmful. Learn
8more in the [moderation guide](https://platform.openai.com/docs/guides/moderation).
9
10### Parameters
11
12- `body ModerationNewParams`
13
14 - `Input param.Field[ModerationNewParamsInputUnion]`
15
16 Input (or inputs) to classify. Can be a single string, an array of strings, or
17 an array of multi-modal input objects similar to other models.
18
19 - `string`
20
21 - `type ModerationNewParamsInputArray []string`
22
23 An array of strings to classify for moderation.
24
25 - `type ModerationNewParamsInputModerationMultiModalArray []ModerationMultiModalInputUnion`
26
27 An array of multi-modal inputs to the moderation model.
28
29 - `type ModerationImageURLInput struct{…}`
30
31 An object describing an image to classify.
32
33 - `ImageURL ModerationImageURLInputImageURL`
34
35 Contains either an image URL or a data URL for a base64 encoded image.
36
37 - `URL string`
38
39 Either a URL of the image or the base64 encoded image data.
40
41 - `Type ImageURL`
42
43 Always `image_url`.
44
45 - `const ImageURLImageURL ImageURL = "image_url"`
46
47 - `type ModerationTextInput struct{…}`
48
49 An object describing text to classify.
50
51 - `Text string`
52
53 A string of text to classify.
54
55 - `Type Text`
56
57 Always `text`.
58
59 - `const TextText Text = "text"`
60
61 - `Model param.Field[ModerationModel]`
62
63 The content moderation model you would like to use. Learn more in
64 [the moderation guide](https://platform.openai.com/docs/guides/moderation), and learn about
65 available models [here](https://platform.openai.com/docs/models#moderation).
66
67 - `string`
68
69 - `type ModerationModel string`
70
71 - `const ModerationModelOmniModerationLatest ModerationModel = "omni-moderation-latest"`
72
73 - `const ModerationModelOmniModeration2024_09_26 ModerationModel = "omni-moderation-2024-09-26"`
74
75 - `const ModerationModelTextModerationLatest ModerationModel = "text-moderation-latest"`
76
77 - `const ModerationModelTextModerationStable ModerationModel = "text-moderation-stable"`
78
79### Returns
80
81- `type ModerationNewResponse struct{…}`
82
83 Represents if a given text input is potentially harmful.
84
85 - `ID string`
86
87 The unique identifier for the moderation request.
88
89 - `Model string`
90
91 The model used to generate the moderation results.
92
93 - `Results []Moderation`
94
95 A list of moderation objects.
96
97 - `Categories ModerationCategories`
98
99 A list of the categories, and whether they are flagged or not.
100
101 - `Harassment bool`
102
103 Content that expresses, incites, or promotes harassing language towards any target.
104
105 - `HarassmentThreatening bool`
106
107 Harassment content that also includes violence or serious harm towards any target.
108
109 - `Hate bool`
110
111 Content that expresses, incites, or promotes hate based on race, gender, ethnicity, religion, nationality, sexual orientation, disability status, or caste. Hateful content aimed at non-protected groups (e.g., chess players) is harassment.
112
113 - `HateThreatening bool`
114
115 Hateful content that also includes violence or serious harm towards the targeted group based on race, gender, ethnicity, religion, nationality, sexual orientation, disability status, or caste.
116
117 - `Illicit bool`
118
119 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.
120
121 - `IllicitViolent bool`
122
123 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.
124
125 - `SelfHarm bool`
126
127 Content that promotes, encourages, or depicts acts of self-harm, such as suicide, cutting, and eating disorders.
128
129 - `SelfHarmInstructions bool`
130
131 Content that encourages performing acts of self-harm, such as suicide, cutting, and eating disorders, or that gives instructions or advice on how to commit such acts.
132
133 - `SelfHarmIntent bool`
134
135 Content where the speaker expresses that they are engaging or intend to engage in acts of self-harm, such as suicide, cutting, and eating disorders.
136
137 - `Sexual bool`
138
139 Content meant to arouse sexual excitement, such as the description of sexual activity, or that promotes sexual services (excluding sex education and wellness).
140
141 - `SexualMinors bool`
142
143 Sexual content that includes an individual who is under 18 years old.
144
145 - `Violence bool`
146
147 Content that depicts death, violence, or physical injury.
148
149 - `ViolenceGraphic bool`
150
151 Content that depicts death, violence, or physical injury in graphic detail.
152
153 - `CategoryAppliedInputTypes ModerationCategoryAppliedInputTypes`
154
155 A list of the categories along with the input type(s) that the score applies to.
156
157 - `Harassment []string`
158
159 The applied input type(s) for the category 'harassment'.
160
161 - `const ModerationCategoryAppliedInputTypesHarassmentText ModerationCategoryAppliedInputTypesHarassment = "text"`
162
163 - `HarassmentThreatening []string`
164
165 The applied input type(s) for the category 'harassment/threatening'.
166
167 - `const ModerationCategoryAppliedInputTypesHarassmentThreateningText ModerationCategoryAppliedInputTypesHarassmentThreatening = "text"`
168
169 - `Hate []string`
170
171 The applied input type(s) for the category 'hate'.
172
173 - `const ModerationCategoryAppliedInputTypesHateText ModerationCategoryAppliedInputTypesHate = "text"`
174
175 - `HateThreatening []string`
176
177 The applied input type(s) for the category 'hate/threatening'.
178
179 - `const ModerationCategoryAppliedInputTypesHateThreateningText ModerationCategoryAppliedInputTypesHateThreatening = "text"`
180
181 - `Illicit []string`
182
183 The applied input type(s) for the category 'illicit'.
184
185 - `const ModerationCategoryAppliedInputTypesIllicitText ModerationCategoryAppliedInputTypesIllicit = "text"`
186
187 - `IllicitViolent []string`
188
189 The applied input type(s) for the category 'illicit/violent'.
190
191 - `const ModerationCategoryAppliedInputTypesIllicitViolentText ModerationCategoryAppliedInputTypesIllicitViolent = "text"`
192
193 - `SelfHarm []string`
194
195 The applied input type(s) for the category 'self-harm'.
196
197 - `const ModerationCategoryAppliedInputTypesSelfHarmText ModerationCategoryAppliedInputTypesSelfHarm = "text"`
198
199 - `const ModerationCategoryAppliedInputTypesSelfHarmImage ModerationCategoryAppliedInputTypesSelfHarm = "image"`
200
201 - `SelfHarmInstructions []string`
202
203 The applied input type(s) for the category 'self-harm/instructions'.
204
205 - `const ModerationCategoryAppliedInputTypesSelfHarmInstructionText ModerationCategoryAppliedInputTypesSelfHarmInstruction = "text"`
206
207 - `const ModerationCategoryAppliedInputTypesSelfHarmInstructionImage ModerationCategoryAppliedInputTypesSelfHarmInstruction = "image"`
208
209 - `SelfHarmIntent []string`
210
211 The applied input type(s) for the category 'self-harm/intent'.
212
213 - `const ModerationCategoryAppliedInputTypesSelfHarmIntentText ModerationCategoryAppliedInputTypesSelfHarmIntent = "text"`
214
215 - `const ModerationCategoryAppliedInputTypesSelfHarmIntentImage ModerationCategoryAppliedInputTypesSelfHarmIntent = "image"`
216
217 - `Sexual []string`
218
219 The applied input type(s) for the category 'sexual'.
220
221 - `const ModerationCategoryAppliedInputTypesSexualText ModerationCategoryAppliedInputTypesSexual = "text"`
222
223 - `const ModerationCategoryAppliedInputTypesSexualImage ModerationCategoryAppliedInputTypesSexual = "image"`
224
225 - `SexualMinors []string`
226
227 The applied input type(s) for the category 'sexual/minors'.
228
229 - `const ModerationCategoryAppliedInputTypesSexualMinorText ModerationCategoryAppliedInputTypesSexualMinor = "text"`
230
231 - `Violence []string`
232
233 The applied input type(s) for the category 'violence'.
234
235 - `const ModerationCategoryAppliedInputTypesViolenceText ModerationCategoryAppliedInputTypesViolence = "text"`
236
237 - `const ModerationCategoryAppliedInputTypesViolenceImage ModerationCategoryAppliedInputTypesViolence = "image"`
238
239 - `ViolenceGraphic []string`
240
241 The applied input type(s) for the category 'violence/graphic'.
242
243 - `const ModerationCategoryAppliedInputTypesViolenceGraphicText ModerationCategoryAppliedInputTypesViolenceGraphic = "text"`
244
245 - `const ModerationCategoryAppliedInputTypesViolenceGraphicImage ModerationCategoryAppliedInputTypesViolenceGraphic = "image"`
246
247 - `CategoryScores ModerationCategoryScores`
248
249 A list of the categories along with their scores as predicted by model.
250
251 - `Harassment float64`
252
253 The score for the category 'harassment'.
254
255 - `HarassmentThreatening float64`
256
257 The score for the category 'harassment/threatening'.
258
259 - `Hate float64`
260
261 The score for the category 'hate'.
262
263 - `HateThreatening float64`
264
265 The score for the category 'hate/threatening'.
266
267 - `Illicit float64`
268
269 The score for the category 'illicit'.
270
271 - `IllicitViolent float64`
272
273 The score for the category 'illicit/violent'.
274
275 - `SelfHarm float64`
276
277 The score for the category 'self-harm'.
278
279 - `SelfHarmInstructions float64`
280
281 The score for the category 'self-harm/instructions'.
282
283 - `SelfHarmIntent float64`
284
285 The score for the category 'self-harm/intent'.
286
287 - `Sexual float64`
288
289 The score for the category 'sexual'.
290
291 - `SexualMinors float64`
292
293 The score for the category 'sexual/minors'.
294
295 - `Violence float64`
296
297 The score for the category 'violence'.
298
299 - `ViolenceGraphic float64`
300
301 The score for the category 'violence/graphic'.
302
303 - `Flagged bool`
304
305 Whether any of the below categories are flagged.
306
307### Example
308
309```go
310package main
311
312import (
313 "context"
314 "fmt"
315
316 "github.com/openai/openai-go"
317 "github.com/openai/openai-go/option"
318)
319
320func main() {
321 client := openai.NewClient(
322 option.WithAPIKey("My API Key"),
323 )
324 moderation, err := client.Moderations.New(context.TODO(), openai.ModerationNewParams{
325 Input: openai.ModerationNewParamsInputUnion{
326 OfString: openai.String("I want to kill them."),
327 },
328 })
329 if err != nil {
330 panic(err.Error())
331 }
332 fmt.Printf("%+v\n", moderation.ID)
333}
334```
335
336#### Response
337
338```json
339{
340 "id": "id",
341 "model": "model",
342 "results": [
343 {
344 "categories": {
345 "harassment": true,
346 "harassment/threatening": true,
347 "hate": true,
348 "hate/threatening": true,
349 "illicit": true,
350 "illicit/violent": true,
351 "self-harm": true,
352 "self-harm/instructions": true,
353 "self-harm/intent": true,
354 "sexual": true,
355 "sexual/minors": true,
356 "violence": true,
357 "violence/graphic": true
358 },
359 "category_applied_input_types": {
360 "harassment": [
361 "text"
362 ],
363 "harassment/threatening": [
364 "text"
365 ],
366 "hate": [
367 "text"
368 ],
369 "hate/threatening": [
370 "text"
371 ],
372 "illicit": [
373 "text"
374 ],
375 "illicit/violent": [
376 "text"
377 ],
378 "self-harm": [
379 "text"
380 ],
381 "self-harm/instructions": [
382 "text"
383 ],
384 "self-harm/intent": [
385 "text"
386 ],
387 "sexual": [
388 "text"
389 ],
390 "sexual/minors": [
391 "text"
392 ],
393 "violence": [
394 "text"
395 ],
396 "violence/graphic": [
397 "text"
398 ]
399 },
400 "category_scores": {
401 "harassment": 0,
402 "harassment/threatening": 0,
403 "hate": 0,
404 "hate/threatening": 0,
405 "illicit": 0,
406 "illicit/violent": 0,
407 "self-harm": 0,
408 "self-harm/instructions": 0,
409 "self-harm/intent": 0,
410 "sexual": 0,
411 "sexual/minors": 0,
412 "violence": 0,
413 "violence/graphic": 0
414 },
415 "flagged": true
416 }
417 ]
418}
419```