Skip to content

Commit f220443

Browse files
authored
Added fields for moderation (#662)
1 parent c5401e9 commit f220443

File tree

2 files changed

+59
-20
lines changed

2 files changed

+59
-20
lines changed

moderation.go

+22-14
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,32 @@ type Result struct {
4444

4545
// ResultCategories represents Categories of Result.
4646
type ResultCategories struct {
47-
Hate bool `json:"hate"`
48-
HateThreatening bool `json:"hate/threatening"`
49-
SelfHarm bool `json:"self-harm"`
50-
Sexual bool `json:"sexual"`
51-
SexualMinors bool `json:"sexual/minors"`
52-
Violence bool `json:"violence"`
53-
ViolenceGraphic bool `json:"violence/graphic"`
47+
Hate bool `json:"hate"`
48+
HateThreatening bool `json:"hate/threatening"`
49+
Harassment bool `json:"harassment"`
50+
HarassmentThreatening bool `json:"harassment/threatening"`
51+
SelfHarm bool `json:"self-harm"`
52+
SelfHarmIntent bool `json:"self-harm/intent"`
53+
SelfHarmInstructions bool `json:"self-harm/instructions"`
54+
Sexual bool `json:"sexual"`
55+
SexualMinors bool `json:"sexual/minors"`
56+
Violence bool `json:"violence"`
57+
ViolenceGraphic bool `json:"violence/graphic"`
5458
}
5559

5660
// ResultCategoryScores represents CategoryScores of Result.
5761
type ResultCategoryScores struct {
58-
Hate float32 `json:"hate"`
59-
HateThreatening float32 `json:"hate/threatening"`
60-
SelfHarm float32 `json:"self-harm"`
61-
Sexual float32 `json:"sexual"`
62-
SexualMinors float32 `json:"sexual/minors"`
63-
Violence float32 `json:"violence"`
64-
ViolenceGraphic float32 `json:"violence/graphic"`
62+
Hate bool `json:"hate"`
63+
HateThreatening bool `json:"hate/threatening"`
64+
Harassment bool `json:"harassment"`
65+
HarassmentThreatening bool `json:"harassment/threatening"`
66+
SelfHarm bool `json:"self-harm"`
67+
SelfHarmIntent bool `json:"self-harm/intent"`
68+
SelfHarmInstructions bool `json:"self-harm/instructions"`
69+
Sexual bool `json:"sexual"`
70+
SexualMinors bool `json:"sexual/minors"`
71+
Violence bool `json:"violence"`
72+
ViolenceGraphic bool `json:"violence/graphic"`
6573
}
6674

6775
// ModerationResponse represents a response structure for moderation API.

moderation_test.go

+37-6
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,49 @@ func handleModerationEndpoint(w http.ResponseWriter, r *http.Request) {
8080
resCat := openai.ResultCategories{}
8181
resCatScore := openai.ResultCategoryScores{}
8282
switch {
83-
case strings.Contains(moderationReq.Input, "kill"):
84-
resCat = openai.ResultCategories{Violence: true}
85-
resCatScore = openai.ResultCategoryScores{Violence: 1}
8683
case strings.Contains(moderationReq.Input, "hate"):
8784
resCat = openai.ResultCategories{Hate: true}
88-
resCatScore = openai.ResultCategoryScores{Hate: 1}
85+
resCatScore = openai.ResultCategoryScores{Hate: true}
86+
87+
case strings.Contains(moderationReq.Input, "hate more"):
88+
resCat = openai.ResultCategories{HateThreatening: true}
89+
resCatScore = openai.ResultCategoryScores{HateThreatening: true}
90+
91+
case strings.Contains(moderationReq.Input, "harass"):
92+
resCat = openai.ResultCategories{Harassment: true}
93+
resCatScore = openai.ResultCategoryScores{Harassment: true}
94+
95+
case strings.Contains(moderationReq.Input, "harass hard"):
96+
resCat = openai.ResultCategories{Harassment: true}
97+
resCatScore = openai.ResultCategoryScores{HarassmentThreatening: true}
98+
8999
case strings.Contains(moderationReq.Input, "suicide"):
90100
resCat = openai.ResultCategories{SelfHarm: true}
91-
resCatScore = openai.ResultCategoryScores{SelfHarm: 1}
101+
resCatScore = openai.ResultCategoryScores{SelfHarm: true}
102+
103+
case strings.Contains(moderationReq.Input, "wanna suicide"):
104+
resCat = openai.ResultCategories{SelfHarmIntent: true}
105+
resCatScore = openai.ResultCategoryScores{SelfHarm: true}
106+
107+
case strings.Contains(moderationReq.Input, "drink bleach"):
108+
resCat = openai.ResultCategories{SelfHarmInstructions: true}
109+
resCatScore = openai.ResultCategoryScores{SelfHarmInstructions: true}
110+
92111
case strings.Contains(moderationReq.Input, "porn"):
93112
resCat = openai.ResultCategories{Sexual: true}
94-
resCatScore = openai.ResultCategoryScores{Sexual: 1}
113+
resCatScore = openai.ResultCategoryScores{Sexual: true}
114+
115+
case strings.Contains(moderationReq.Input, "child porn"):
116+
resCat = openai.ResultCategories{SexualMinors: true}
117+
resCatScore = openai.ResultCategoryScores{SexualMinors: true}
118+
119+
case strings.Contains(moderationReq.Input, "kill"):
120+
resCat = openai.ResultCategories{Violence: true}
121+
resCatScore = openai.ResultCategoryScores{Violence: true}
122+
123+
case strings.Contains(moderationReq.Input, "corpse"):
124+
resCat = openai.ResultCategories{ViolenceGraphic: true}
125+
resCatScore = openai.ResultCategoryScores{ViolenceGraphic: true}
95126
}
96127

97128
result := openai.Result{Categories: resCat, CategoryScores: resCatScore, Flagged: true}

0 commit comments

Comments
 (0)