-
Notifications
You must be signed in to change notification settings - Fork 4
/
moderation_test.go
84 lines (80 loc) · 2.51 KB
/
moderation_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright (c) 2022 0x9ef. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
package openai
import (
"context"
"log"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestModerate(t *testing.T) {
testCases := []struct {
name string
input string
expectedHate bool
expectedHateThreating bool
expectedSelfHarm bool
expectedSexual bool
expectedSexualMinors bool
expectedViolence bool
expectedVioenceGraphic bool
}{
{
name: "success:moderate hate",
input: "Im going to kill all people!",
expectedHate: true,
},
{
name: "success:moderate hate threating",
input: "I kill every white man",
expectedHateThreating: true,
},
{
name: "success:moderate self harm",
input: "Imma going to suicide because I hate myself",
expectedSelfHarm: true,
},
{
name: "success:moderate sexual",
input: "Naked girl",
expectedSexual: true,
},
{
name: "success:moderate sexual minors",
input: "Naked girl under 18",
expectedSexualMinors: true,
},
{
name: "success:moderate violence",
input: "You have to beat up muslims",
expectedViolence: true,
},
}
e := New(os.Getenv("OPENAI_KEY"))
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
r, err := e.Moderate(context.Background(), tc.input)
if err != nil {
log.Fatal(err)
}
switch {
case tc.expectedHate:
assert.Equalf(t, tc.expectedHate, r.Results[0].Categories.Hate, "expected hate")
case tc.expectedHateThreating:
assert.Equal(t, tc.expectedHateThreating, r.Results[0].Categories.HateThreatening, "expected hate threating")
case tc.expectedSelfHarm:
assert.Equal(t, tc.expectedSelfHarm, r.Results[0].Categories.SelfHarm, "expected self harm")
case tc.expectedSexual:
assert.Equal(t, tc.expectedSexual, r.Results[0].Categories.Sexual, "expected sexual")
case tc.expectedSexualMinors:
assert.Equal(t, tc.expectedSexualMinors, r.Results[0].Categories.SexualMinors, "expected sexual minors")
case tc.expectedViolence:
assert.Equal(t, tc.expectedViolence, r.Results[0].Categories.Violence, "expected violence")
case tc.expectedVioenceGraphic:
assert.Equal(t, tc.expectedVioenceGraphic, r.Results[0].Categories.ViolenceGraphic, "expected violence graphic")
}
})
}
}