Check for GPT-4 models (#169)

* add chat gpt4 model support (#158)

* remove check for gpt4 for CreateCompletion

* test for model check

---------

Co-authored-by: aeieli <aeliieli@gmail.com>
This commit is contained in:
sashabaranov
2023-03-16 10:43:41 +04:00
committed by GitHub
parent c34bc77f1a
commit abffeceb71
2 changed files with 21 additions and 1 deletions

View File

@@ -66,7 +66,9 @@ func (c *Client) CreateChatCompletion(
request ChatCompletionRequest,
) (response ChatCompletionResponse, err error) {
model := request.Model
if model != GPT3Dot5Turbo0301 && model != GPT3Dot5Turbo {
switch model {
case GPT3Dot5Turbo0301, GPT3Dot5Turbo, GPT4, GPT40314, GPT432K0314, GPT432K:
default:
err = ErrChatCompletionInvalidModel
return
}

View File

@@ -6,6 +6,7 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
@@ -15,6 +16,23 @@ import (
"time"
)
func TestCompletionsWrongModel(t *testing.T) {
config := DefaultConfig("whatever")
config.BaseURL = "http://localhost/v1"
client := NewClientWithConfig(config)
_, err := client.CreateCompletion(
context.Background(),
CompletionRequest{
MaxTokens: 5,
Model: GPT3Dot5Turbo,
},
)
if !errors.Is(err, ErrCompletionUnsupportedModel) {
t.Fatalf("CreateCompletion should return ErrCompletionUnsupportedModel, but returned: %v", err)
}
}
// TestCompletions Tests the completions endpoint of the API using the mocked server.
func TestCompletions(t *testing.T) {
server := test.NewTestServer()