Added fields for moderation (#662)
This commit is contained in:
@@ -44,24 +44,32 @@ type Result struct {
|
|||||||
|
|
||||||
// ResultCategories represents Categories of Result.
|
// ResultCategories represents Categories of Result.
|
||||||
type ResultCategories struct {
|
type ResultCategories struct {
|
||||||
Hate bool `json:"hate"`
|
Hate bool `json:"hate"`
|
||||||
HateThreatening bool `json:"hate/threatening"`
|
HateThreatening bool `json:"hate/threatening"`
|
||||||
SelfHarm bool `json:"self-harm"`
|
Harassment bool `json:"harassment"`
|
||||||
Sexual bool `json:"sexual"`
|
HarassmentThreatening bool `json:"harassment/threatening"`
|
||||||
SexualMinors bool `json:"sexual/minors"`
|
SelfHarm bool `json:"self-harm"`
|
||||||
Violence bool `json:"violence"`
|
SelfHarmIntent bool `json:"self-harm/intent"`
|
||||||
ViolenceGraphic bool `json:"violence/graphic"`
|
SelfHarmInstructions bool `json:"self-harm/instructions"`
|
||||||
|
Sexual bool `json:"sexual"`
|
||||||
|
SexualMinors bool `json:"sexual/minors"`
|
||||||
|
Violence bool `json:"violence"`
|
||||||
|
ViolenceGraphic bool `json:"violence/graphic"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResultCategoryScores represents CategoryScores of Result.
|
// ResultCategoryScores represents CategoryScores of Result.
|
||||||
type ResultCategoryScores struct {
|
type ResultCategoryScores struct {
|
||||||
Hate float32 `json:"hate"`
|
Hate bool `json:"hate"`
|
||||||
HateThreatening float32 `json:"hate/threatening"`
|
HateThreatening bool `json:"hate/threatening"`
|
||||||
SelfHarm float32 `json:"self-harm"`
|
Harassment bool `json:"harassment"`
|
||||||
Sexual float32 `json:"sexual"`
|
HarassmentThreatening bool `json:"harassment/threatening"`
|
||||||
SexualMinors float32 `json:"sexual/minors"`
|
SelfHarm bool `json:"self-harm"`
|
||||||
Violence float32 `json:"violence"`
|
SelfHarmIntent bool `json:"self-harm/intent"`
|
||||||
ViolenceGraphic float32 `json:"violence/graphic"`
|
SelfHarmInstructions bool `json:"self-harm/instructions"`
|
||||||
|
Sexual bool `json:"sexual"`
|
||||||
|
SexualMinors bool `json:"sexual/minors"`
|
||||||
|
Violence bool `json:"violence"`
|
||||||
|
ViolenceGraphic bool `json:"violence/graphic"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ModerationResponse represents a response structure for moderation API.
|
// ModerationResponse represents a response structure for moderation API.
|
||||||
|
|||||||
@@ -80,18 +80,49 @@ func handleModerationEndpoint(w http.ResponseWriter, r *http.Request) {
|
|||||||
resCat := openai.ResultCategories{}
|
resCat := openai.ResultCategories{}
|
||||||
resCatScore := openai.ResultCategoryScores{}
|
resCatScore := openai.ResultCategoryScores{}
|
||||||
switch {
|
switch {
|
||||||
case strings.Contains(moderationReq.Input, "kill"):
|
|
||||||
resCat = openai.ResultCategories{Violence: true}
|
|
||||||
resCatScore = openai.ResultCategoryScores{Violence: 1}
|
|
||||||
case strings.Contains(moderationReq.Input, "hate"):
|
case strings.Contains(moderationReq.Input, "hate"):
|
||||||
resCat = openai.ResultCategories{Hate: true}
|
resCat = openai.ResultCategories{Hate: true}
|
||||||
resCatScore = openai.ResultCategoryScores{Hate: 1}
|
resCatScore = openai.ResultCategoryScores{Hate: true}
|
||||||
|
|
||||||
|
case strings.Contains(moderationReq.Input, "hate more"):
|
||||||
|
resCat = openai.ResultCategories{HateThreatening: true}
|
||||||
|
resCatScore = openai.ResultCategoryScores{HateThreatening: true}
|
||||||
|
|
||||||
|
case strings.Contains(moderationReq.Input, "harass"):
|
||||||
|
resCat = openai.ResultCategories{Harassment: true}
|
||||||
|
resCatScore = openai.ResultCategoryScores{Harassment: true}
|
||||||
|
|
||||||
|
case strings.Contains(moderationReq.Input, "harass hard"):
|
||||||
|
resCat = openai.ResultCategories{Harassment: true}
|
||||||
|
resCatScore = openai.ResultCategoryScores{HarassmentThreatening: true}
|
||||||
|
|
||||||
case strings.Contains(moderationReq.Input, "suicide"):
|
case strings.Contains(moderationReq.Input, "suicide"):
|
||||||
resCat = openai.ResultCategories{SelfHarm: true}
|
resCat = openai.ResultCategories{SelfHarm: true}
|
||||||
resCatScore = openai.ResultCategoryScores{SelfHarm: 1}
|
resCatScore = openai.ResultCategoryScores{SelfHarm: true}
|
||||||
|
|
||||||
|
case strings.Contains(moderationReq.Input, "wanna suicide"):
|
||||||
|
resCat = openai.ResultCategories{SelfHarmIntent: true}
|
||||||
|
resCatScore = openai.ResultCategoryScores{SelfHarm: true}
|
||||||
|
|
||||||
|
case strings.Contains(moderationReq.Input, "drink bleach"):
|
||||||
|
resCat = openai.ResultCategories{SelfHarmInstructions: true}
|
||||||
|
resCatScore = openai.ResultCategoryScores{SelfHarmInstructions: true}
|
||||||
|
|
||||||
case strings.Contains(moderationReq.Input, "porn"):
|
case strings.Contains(moderationReq.Input, "porn"):
|
||||||
resCat = openai.ResultCategories{Sexual: true}
|
resCat = openai.ResultCategories{Sexual: true}
|
||||||
resCatScore = openai.ResultCategoryScores{Sexual: 1}
|
resCatScore = openai.ResultCategoryScores{Sexual: true}
|
||||||
|
|
||||||
|
case strings.Contains(moderationReq.Input, "child porn"):
|
||||||
|
resCat = openai.ResultCategories{SexualMinors: true}
|
||||||
|
resCatScore = openai.ResultCategoryScores{SexualMinors: true}
|
||||||
|
|
||||||
|
case strings.Contains(moderationReq.Input, "kill"):
|
||||||
|
resCat = openai.ResultCategories{Violence: true}
|
||||||
|
resCatScore = openai.ResultCategoryScores{Violence: true}
|
||||||
|
|
||||||
|
case strings.Contains(moderationReq.Input, "corpse"):
|
||||||
|
resCat = openai.ResultCategories{ViolenceGraphic: true}
|
||||||
|
resCatScore = openai.ResultCategoryScores{ViolenceGraphic: true}
|
||||||
}
|
}
|
||||||
|
|
||||||
result := openai.Result{Categories: resCat, CategoryScores: resCatScore, Flagged: true}
|
result := openai.Result{Categories: resCat, CategoryScores: resCatScore, Flagged: true}
|
||||||
|
|||||||
Reference in New Issue
Block a user