Skip to content

Commit

Permalink
test(moderation): add testcase for ModerationItemTypeImageURL
Browse files Browse the repository at this point in the history
  • Loading branch information
chenhhA committed Dec 15, 2024
1 parent ab83747 commit afd0628
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions moderation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ func TestModerations(t *testing.T) {
},
Model: openai.ModerationOmniLatest,
},
openai.ModerationArrayRequest{
Input: []openai.ModerationRequestItem{
{
Type: openai.ModerationItemTypeImageURL,
ImageURL: openai.ModerationImageURL{
URL: "https://cdn.openai.com/API/images/harass.png",
},
},
},
Model: openai.ModerationOmniLatest,
},
}

for _, input := range requestInputs {
Expand Down Expand Up @@ -212,6 +223,13 @@ func handleModerationEndpoint(w http.ResponseWriter, r *http.Request) {
resCatApplied = openai.CategoryAppliedInputType{
IllicitViolent: []openai.ModerationItemType{openai.ModerationItemTypeText},
}
case moderationReq.Input[i].Type == openai.ModerationItemTypeImageURL &&
moderationReq.Input[i].ImageURL.URL == "https://cdn.openai.com/API/images/harass.png":
resCat = openai.ResultCategories{Harassment: true}
resCatScore = openai.ResultCategoryScores{Harassment: 1}
resCatApplied = openai.CategoryAppliedInputType{
Harassment: []openai.ModerationItemType{openai.ModerationItemTypeImageURL},
}
}

result := openai.Result{
Expand Down

0 comments on commit afd0628

Please sign in to comment.