Skip to content

Commit 8aeb601

Browse files
committed
fix: failing tests, bug
1 parent b7e25fa commit 8aeb601

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

chat.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const (
4444

4545
type ChatCompletionRequest struct {
4646
// (Required)
47-
// ID of the model to use. Currently, only gpt-3.5-turbo and gpt-3.5-turbo-0301 are supported.
47+
// ID of the model to use.
4848
Model ChatGPTModel `json:"model"`
4949

5050
// Required
@@ -157,16 +157,22 @@ func validate(req *ChatCompletionRequest) error {
157157
return chatgpt_errors.ErrNoMessages
158158
}
159159

160+
isAllowed := false
161+
160162
allowedModels := []ChatGPTModel{
161163
GPT35Turbo, GPT35Turbo0301, GPT35Turbo0613, GPT35Turbo16k, GPT35Turbo16k0613, GPT4, GPT4_0314, GPT4_0613, GPT4_32k, GPT4_32k_0314, GPT4_32k_0613,
162164
}
163165

164166
for _, model := range allowedModels {
165-
if req.Model != model {
166-
return chatgpt_errors.ErrInvalidModel
167+
if req.Model == model {
168+
isAllowed = true
167169
}
168170
}
169171

172+
if !isAllowed {
173+
return chatgpt_errors.ErrInvalidModel
174+
}
175+
170176
for _, message := range req.Messages {
171177
if message.Role != ChatGPTModelRoleUser && message.Role != ChatGPTModelRoleSystem && message.Role != ChatGPTModelRoleAssistant {
172178
return chatgpt_errors.ErrInvalidRole

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ module github.com/ayush6624/go-chatgpt
22

33
go 1.20
44

5+
require github.com/stretchr/testify v1.8.2
6+
57
require (
68
github.com/davecgh/go-spew v1.1.1 // indirect
79
github.com/pmezard/go-difflib v1.0.0 // indirect
8-
github.com/stretchr/objx v0.5.0 // indirect
9-
github.com/stretchr/testify v1.8.2 // indirect
1010
gopkg.in/yaml.v3 v3.0.1 // indirect
1111
)

go.sum

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
55
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
66
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
77
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
8-
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
98
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
109
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
1110
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
1211
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
1312
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
13+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
1414
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1515
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
1616
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

utils/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var (
77
ErrAPIKeyRequired = errors.New("API Key is required")
88

99
// ErrInvalidModel is returned when the model is invalid
10-
ErrInvalidModel = errors.New("invalid model. Only `gpt-3.5-turbo` and `gpt-3.5-turbo-0301` are supported")
10+
ErrInvalidModel = errors.New("invalid model")
1111

1212
// ErrNoMessages is returned when no messages are provided
1313
ErrNoMessages = errors.New("no messages provided")

0 commit comments

Comments
 (0)