|
| 1 | +--- |
| 2 | +title: Moderations |
| 3 | +--- |
| 4 | + |
| 5 | +!!! Note |
| 6 | + |
| 7 | + Please build the client before calling, the build code is as follows: |
| 8 | + |
| 9 | + ```java |
| 10 | + OpenAiClient client = OpenAiClient.builder() |
| 11 | + .apiHost("https://api.openai.com") |
| 12 | + .apiKey(System.getProperty("openai.token")) |
| 13 | + .build(); |
| 14 | + ``` |
| 15 | + |
| 16 | + `System.getProperty("openai.token")` is the key to access the API authorization. |
| 17 | + |
| 18 | +### Create moderation |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +Classifies if text violates OpenAI's Content Policy |
| 23 | + |
| 24 | +```java |
| 25 | +ModerationEntity configure = ModerationEntity.builder() |
| 26 | + .inputs(Lists.newArrayList("Hello OpenAi Java SDK")) |
| 27 | + .build(); |
| 28 | +client.moderations(configure); |
| 29 | +``` |
| 30 | + |
| 31 | +Returns |
| 32 | + |
| 33 | +```json |
| 34 | +{ |
| 35 | + "id": "modr-XXXXX", |
| 36 | + "model": "text-moderation-005", |
| 37 | + "results": [ |
| 38 | + { |
| 39 | + "flagged": true, |
| 40 | + "categories": { |
| 41 | + "sexual": false, |
| 42 | + "hate": false, |
| 43 | + "harassment": false, |
| 44 | + "self-harm": false, |
| 45 | + "sexual/minors": false, |
| 46 | + "hate/threatening": false, |
| 47 | + "violence/graphic": false, |
| 48 | + "self-harm/intent": false, |
| 49 | + "self-harm/instructions": false, |
| 50 | + "harassment/threatening": true, |
| 51 | + "violence": true |
| 52 | + }, |
| 53 | + "category_scores": { |
| 54 | + "sexual": 1.2282071e-06, |
| 55 | + "hate": 0.010696256, |
| 56 | + "harassment": 0.29842457, |
| 57 | + "self-harm": 1.5236925e-08, |
| 58 | + "sexual/minors": 5.7246268e-08, |
| 59 | + "hate/threatening": 0.0060676364, |
| 60 | + "violence/graphic": 4.435014e-06, |
| 61 | + "self-harm/intent": 8.098441e-10, |
| 62 | + "self-harm/instructions": 2.8498655e-11, |
| 63 | + "harassment/threatening": 0.63055265, |
| 64 | + "violence": 0.99011886 |
| 65 | + } |
| 66 | + } |
| 67 | + ] |
| 68 | +} |
| 69 | +``` |
0 commit comments