-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
402 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
title: 客户 | ||
title: 用户案例 | ||
|
||
hide: | ||
- navigation | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
--- | ||
title: Moderations | ||
--- | ||
|
||
!!! Note | ||
|
||
Please build the client before calling, the build code is as follows: | ||
|
||
```java | ||
OpenAiClient client = OpenAiClient.builder() | ||
.apiHost("https://api.openai.com") | ||
.apiKey(System.getProperty("openai.token")) | ||
.build(); | ||
``` | ||
|
||
`System.getProperty("openai.token")` is the key to access the API authorization. | ||
|
||
### Create moderation | ||
|
||
--- | ||
|
||
Classifies if text violates OpenAI's Content Policy | ||
|
||
```java | ||
ModerationEntity configure = ModerationEntity.builder() | ||
.inputs(Lists.newArrayList("Hello OpenAi Java SDK")) | ||
.build(); | ||
client.moderations(configure); | ||
``` | ||
|
||
Returns | ||
|
||
```json | ||
{ | ||
"id": "modr-XXXXX", | ||
"model": "text-moderation-005", | ||
"results": [ | ||
{ | ||
"flagged": true, | ||
"categories": { | ||
"sexual": false, | ||
"hate": false, | ||
"harassment": false, | ||
"self-harm": false, | ||
"sexual/minors": false, | ||
"hate/threatening": false, | ||
"violence/graphic": false, | ||
"self-harm/intent": false, | ||
"self-harm/instructions": false, | ||
"harassment/threatening": true, | ||
"violence": true | ||
}, | ||
"category_scores": { | ||
"sexual": 1.2282071e-06, | ||
"hate": 0.010696256, | ||
"harassment": 0.29842457, | ||
"self-harm": 1.5236925e-08, | ||
"sexual/minors": 5.7246268e-08, | ||
"hate/threatening": 0.0060676364, | ||
"violence/graphic": 4.435014e-06, | ||
"self-harm/intent": 8.098441e-10, | ||
"self-harm/instructions": 2.8498655e-11, | ||
"harassment/threatening": 0.63055265, | ||
"violence": 0.99011886 | ||
} | ||
} | ||
] | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
--- | ||
title: Moderations | ||
--- | ||
|
||
!!! Note | ||
|
||
调用前请先构建客户端,构建代码如下: | ||
|
||
```java | ||
OpenAiClient client = OpenAiClient.builder() | ||
.apiHost("https://api.openai.com") | ||
.apiKey(System.getProperty("openai.token")) | ||
.build(); | ||
``` | ||
|
||
`System.getProperty("openai.token")` 是访问 API 授权的关键。 | ||
|
||
### Create moderation | ||
|
||
--- | ||
|
||
对文本是否违反 OpenAI 的内容政策进行分类 | ||
|
||
```java | ||
ModerationEntity configure = ModerationEntity.builder() | ||
.inputs(Lists.newArrayList("Hello OpenAi Java SDK")) | ||
.build(); | ||
client.moderations(configure); | ||
``` | ||
|
||
Returns | ||
|
||
```json | ||
{ | ||
"id": "modr-XXXXX", | ||
"model": "text-moderation-005", | ||
"results": [ | ||
{ | ||
"flagged": true, | ||
"categories": { | ||
"sexual": false, | ||
"hate": false, | ||
"harassment": false, | ||
"self-harm": false, | ||
"sexual/minors": false, | ||
"hate/threatening": false, | ||
"violence/graphic": false, | ||
"self-harm/intent": false, | ||
"self-harm/instructions": false, | ||
"harassment/threatening": true, | ||
"violence": true | ||
}, | ||
"category_scores": { | ||
"sexual": 1.2282071e-06, | ||
"hate": 0.010696256, | ||
"harassment": 0.29842457, | ||
"self-harm": 1.5236925e-08, | ||
"sexual/minors": 5.7246268e-08, | ||
"hate/threatening": 0.0060676364, | ||
"violence/graphic": 4.435014e-06, | ||
"self-harm/intent": 8.098441e-10, | ||
"self-harm/instructions": 2.8498655e-11, | ||
"harassment/threatening": 0.63055265, | ||
"violence": 0.99011886 | ||
} | ||
} | ||
] | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/org/devlive/sdk/openai/entity/CategoryEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.devlive.sdk.openai.entity; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Data; | ||
|
||
@Data | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class CategoryEntity | ||
{ | ||
@JsonProperty(value = "sexual") | ||
private Object sexual; | ||
|
||
@JsonProperty(value = "hate") | ||
private Object hate; | ||
|
||
@JsonProperty(value = "harassment") | ||
private Object harassment; | ||
|
||
@JsonProperty(value = "self-harm") | ||
private Object selfHarm; | ||
|
||
@JsonProperty(value = "sexual/minors") | ||
private Object sexualMinors; | ||
|
||
@JsonProperty(value = "hate/threatening") | ||
private Object hateThreatening; | ||
|
||
@JsonProperty(value = "violence/graphic") | ||
private Object violenceGraphic; | ||
|
||
@JsonProperty(value = "self-harm/intent") | ||
private Object selfHarmIntent; | ||
|
||
@JsonProperty(value = "self-harm/instructions") | ||
private Object selfHarmInstructions; | ||
|
||
@JsonProperty(value = "harassment/threatening") | ||
private Object harassmentThreatening; | ||
|
||
@JsonProperty(value = "violence") | ||
private Object violence; | ||
} |
70 changes: 70 additions & 0 deletions
70
src/main/java/org/devlive/sdk/openai/entity/ModerationEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package org.devlive.sdk.openai.entity; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
import org.apache.commons.lang3.ObjectUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.devlive.sdk.openai.exception.ParamException; | ||
import org.devlive.sdk.openai.model.ModerationModel; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
@Builder | ||
@ToString | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class ModerationEntity | ||
{ | ||
/** | ||
* The input text to classify | ||
* 要分类的输入文本 | ||
*/ | ||
@JsonProperty(value = "input") | ||
private List<String> inputs; | ||
|
||
@JsonProperty(value = "model") | ||
private String model; | ||
|
||
private ModerationEntity(ModerationEntityBuilder builder) | ||
{ | ||
if (ObjectUtils.isEmpty(builder.inputs)) { | ||
builder.inputs(null); | ||
} | ||
this.inputs = builder.inputs; | ||
|
||
if (StringUtils.isEmpty(builder.model)) { | ||
builder.model(ModerationModel.TEXT_MODERATION_LATEST); | ||
} | ||
this.model = builder.model; | ||
} | ||
|
||
public static class ModerationEntityBuilder | ||
{ | ||
public ModerationEntityBuilder inputs(List<String> inputs) | ||
{ | ||
if (ObjectUtils.isEmpty(inputs) || inputs.size() == 0) { | ||
throw new ParamException("Invalid inputs must be non-empty"); | ||
} | ||
this.inputs = inputs; | ||
return this; | ||
} | ||
|
||
public ModerationEntityBuilder model(ModerationModel model) | ||
{ | ||
this.model = model.getName(); | ||
return this; | ||
} | ||
|
||
public ModerationEntity build() | ||
{ | ||
return new ModerationEntity(this); | ||
} | ||
} | ||
} |
Oops, something went wrong.