diff --git a/moderation.go b/moderation.go index 3b1858c02..a32f123f3 100644 --- a/moderation.go +++ b/moderation.go @@ -16,7 +16,8 @@ import ( const ( ModerationTextStable = "text-moderation-stable" ModerationTextLatest = "text-moderation-latest" - ModerationText001 = "text-moderation-001" + // Deprecated: use ModerationTextStable and ModerationTextLatest instead. + ModerationText001 = "text-moderation-001" ) var ( diff --git a/moderation_test.go b/moderation_test.go index 72176636d..68f9565e1 100644 --- a/moderation_test.go +++ b/moderation_test.go @@ -27,16 +27,39 @@ func TestModerations(t *testing.T) { checks.NoError(t, err, "Moderation error") } -// TestModerationsWithIncorrectModel Tests passing an incorrect model to Moderations request. -func TestModerationsWithIncorrectModel(t *testing.T) { +// TestModerationsWithIncorrectModel Tests passing valid and invalid models to moderations endpoint. +func TestModerationsWithDifferentModelOptions(t *testing.T) { + var modelOptions []struct { + model string + expect error + } + modelOptions = append(modelOptions, + getModerationModelTestOption(GPT3Dot5Turbo, ErrModerationInvalidModel), + getModerationModelTestOption(ModerationTextStable, nil), + getModerationModelTestOption(ModerationTextLatest, nil), + getModerationModelTestOption("", nil), + ) client, server, teardown := setupOpenAITestServer() defer teardown() server.RegisterHandler("/v1/moderations", handleModerationEndpoint) - _, err := client.Moderations(context.Background(), ModerationRequest{ - Model: GPT3Dot5Turbo, - Input: "I want to kill them.", - }) - checks.ErrorIs(t, err, ErrModerationInvalidModel) + for _, modelTest := range modelOptions { + _, err := client.Moderations(context.Background(), ModerationRequest{ + Model: modelTest.model, + Input: "I want to kill them.", + }) + checks.ErrorIs(t, err, modelTest.expect, + fmt.Sprintf("Moderations(..) expects err: %v, actual err:%v", modelTest.expect, err)) + } +} + +func getModerationModelTestOption(model string, expect error) struct { + model string + expect error +} { + return struct { + model string + expect error + }{model: model, expect: expect} } // handleModerationEndpoint Handles the moderation endpoint by the test server.