-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmoderations.go
57 lines (48 loc) · 1.92 KB
/
moderations.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
package goopenai
import (
"context"
"encoding/json"
)
type CreateModerationsRequest struct {
Input StrArray `json:"input,omitempty"`
Model string `json:"model,omitempty"`
}
type CreateModerationsResponse struct {
ID string `json:"id,omitempty"`
Model string `json:"model,omitempty"`
Results []CreateModerationsResult `json:"results,omitempty"`
}
type CreateModerationsResult struct {
Categories CreateModerationsCategories `json:"categories,omitempty"`
CategoryScores CreateModerationsCategoriesScores `json:"category_scores,omitempty"`
Flagged bool `json:"flagged,omitempty"`
}
type CreateModerationsCategories struct {
Hate bool `json:"hate,omitempty"`
HateThreatening bool `json:"hate/threatening,omitempty"`
SelfHarm bool `json:"self-harm,omitempty"`
Sexual bool `json:"sexual,omitempty"`
SexualMinors bool `json:"sexual/minors,omitempty"`
Violence bool `json:"violence,omitempty"`
ViolenceGraphic bool `json:"violence/graphic,omitempty"`
}
type CreateModerationsCategoriesScores struct {
Hate float64 `json:"hate,omitempty"`
HateThreatening float64 `json:"hate/threatening,omitempty"`
SelfHarm float64 `json:"self-harm,omitempty"`
Sexual float64 `json:"sexual,omitempty"`
SexualMinors float64 `json:"sexual/minors,omitempty"`
Violence float64 `json:"violence,omitempty"`
ViolenceGraphic float64 `json:"violence/graphic,omitempty"`
}
func (c *Client) CreateModerationsRaw(ctx context.Context, r *CreateModerationsRequest) ([]byte, error) {
return c.Post(ctx, moderationsUrl, r)
}
func (c *Client) CreateModerations(ctx context.Context, r *CreateModerationsRequest) (response *CreateModerationsResponse, err error) {
raw, err := c.CreateModerationsRaw(ctx, r)
if err != nil {
return nil, err
}
err = json.Unmarshal(raw, &response)
return response, err
}