Skip to content

Commit abffece

Browse files
sashabaranovaeieli
andauthored
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 <[email protected]>
1 parent c34bc77 commit abffece

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

chat.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ func (c *Client) CreateChatCompletion(
6666
request ChatCompletionRequest,
6767
) (response ChatCompletionResponse, err error) {
6868
model := request.Model
69-
if model != GPT3Dot5Turbo0301 && model != GPT3Dot5Turbo {
69+
switch model {
70+
case GPT3Dot5Turbo0301, GPT3Dot5Turbo, GPT4, GPT40314, GPT432K0314, GPT432K:
71+
default:
7072
err = ErrChatCompletionInvalidModel
7173
return
7274
}

completion_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"context"
88
"encoding/json"
9+
"errors"
910
"fmt"
1011
"io"
1112
"net/http"
@@ -15,6 +16,23 @@ import (
1516
"time"
1617
)
1718

19+
func TestCompletionsWrongModel(t *testing.T) {
20+
config := DefaultConfig("whatever")
21+
config.BaseURL = "http://localhost/v1"
22+
client := NewClientWithConfig(config)
23+
24+
_, err := client.CreateCompletion(
25+
context.Background(),
26+
CompletionRequest{
27+
MaxTokens: 5,
28+
Model: GPT3Dot5Turbo,
29+
},
30+
)
31+
if !errors.Is(err, ErrCompletionUnsupportedModel) {
32+
t.Fatalf("CreateCompletion should return ErrCompletionUnsupportedModel, but returned: %v", err)
33+
}
34+
}
35+
1836
// TestCompletions Tests the completions endpoint of the API using the mocked server.
1937
func TestCompletions(t *testing.T) {
2038
server := test.NewTestServer()

0 commit comments

Comments
 (0)