refactor: Refactor endpoint and model compatibility check (#180)

* Add model check for chat stream

* Sync model checks

* Fix typo

* Fix functino

* refactor: Refactor endpoint and model compatibility check

* apply review suggestions

* minor fix

* invert return boolean flag

* fix test
This commit is contained in:
Jo
2023-03-22 21:46:08 +08:00
committed by GitHub
parent 428839400a
commit 2ebb265e71
8 changed files with 94 additions and 13 deletions

10
chat.go
View File

@@ -14,8 +14,8 @@ const (
)
var (
ErrChatCompletionInvalidModel = errors.New("currently, only gpt-3.5-turbo and gpt-3.5-turbo-0301 are supported") //nolint:lll
ErrChatCompletionStreamNotSupported = errors.New("streaming is not supported with this method, please use CreateChatCompletionStream") //nolint:lll
ErrChatCompletionInvalidModel = errors.New("this model is not supported with this method, please use CreateCompletion client method instead") //nolint:lll
ErrChatCompletionStreamNotSupported = errors.New("streaming is not supported with this method, please use CreateChatCompletionStream") //nolint:lll
)
type ChatCompletionMessage struct {
@@ -71,14 +71,12 @@ func (c *Client) CreateChatCompletion(
return
}
switch request.Model {
case GPT3Dot5Turbo0301, GPT3Dot5Turbo, GPT4, GPT40314, GPT432K0314, GPT432K:
default:
urlSuffix := "/chat/completions"
if !checkEndpointSupportsModel(urlSuffix, request.Model) {
err = ErrChatCompletionInvalidModel
return
}
urlSuffix := "/chat/completions"
req, err := c.requestBuilder.build(ctx, http.MethodPost, c.fullURL(urlSuffix), request)
if err != nil {
return