You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Check if the model param is valid for moderations endpoint (#437)
* chore: check for models before sending moderation requets to openai endpoint
* chore: table driven tests to include more model cases for moderations endpoint
Copy file name to clipboardExpand all lines: moderation.go
+16-1Lines changed: 16 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,7 @@ package openai
2
2
3
3
import (
4
4
"context"
5
+
"errors"
5
6
"net/http"
6
7
)
7
8
@@ -15,9 +16,19 @@ import (
15
16
const (
16
17
ModerationTextStable="text-moderation-stable"
17
18
ModerationTextLatest="text-moderation-latest"
18
-
ModerationText001="text-moderation-001"
19
+
// Deprecated: use ModerationTextStable and ModerationTextLatest instead.
20
+
ModerationText001="text-moderation-001"
19
21
)
20
22
23
+
var (
24
+
ErrModerationInvalidModel=errors.New("this model is not supported with moderation, please use text-moderation-stable or text-moderation-latest instead") //nolint:lll
25
+
)
26
+
27
+
varvalidModerationModel=map[string]struct{}{
28
+
ModerationTextStable: {},
29
+
ModerationTextLatest: {},
30
+
}
31
+
21
32
// ModerationRequest represents a request structure for moderation API.
22
33
typeModerationRequeststruct {
23
34
Inputstring`json:"input,omitempty"`
@@ -63,6 +74,10 @@ type ModerationResponse struct {
63
74
// Moderations — perform a moderation api call over a string.
64
75
// Input can be an array or slice but a string will reduce the complexity.
0 commit comments