Skip to content

Commit

Permalink
Check for GPT-4 models (sashabaranov#169)
Browse files Browse the repository at this point in the history
* add chat gpt4 model support (sashabaranov#158)

* remove check for gpt4 for CreateCompletion

* test for model check

---------

Co-authored-by: aeieli <aeliieli@gmail.com>
  • Loading branch information
sashabaranov and aeieli authored Mar 16, 2023
1 parent c34bc77 commit abffece
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
18 changes: 18 additions & 0 deletions completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand All @@ -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()
Expand Down

0 comments on commit abffece

Please sign in to comment.