Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix integration test #762

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 37 additions & 27 deletions api_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestAPI(t *testing.T) {
_, err = c.ListEngines(ctx)
checks.NoError(t, err, "ListEngines error")

_, err = c.GetEngine(ctx, "davinci")
_, err = c.GetEngine(ctx, openai.GPT3Davinci002)
checks.NoError(t, err, "GetEngine error")

fileRes, err := c.ListFiles(ctx)
Expand All @@ -42,7 +42,7 @@ func TestAPI(t *testing.T) {
"The food was delicious and the waiter",
"Other examples of embedding request",
},
Model: openai.AdaSearchQuery,
Model: openai.AdaEmbeddingV2,
}
_, err = c.CreateEmbeddings(ctx, embeddingReq)
checks.NoError(t, err, "Embedding error")
Expand Down Expand Up @@ -77,31 +77,6 @@ func TestAPI(t *testing.T) {
)
checks.NoError(t, err, "CreateChatCompletion (with name) returned error")

stream, err := c.CreateCompletionStream(ctx, openai.CompletionRequest{
Prompt: "Ex falso quodlibet",
Model: openai.GPT3Ada,
MaxTokens: 5,
Stream: true,
})
checks.NoError(t, err, "CreateCompletionStream returned error")
defer stream.Close()

counter := 0
for {
_, err = stream.Recv()
if err != nil {
if errors.Is(err, io.EOF) {
break
}
t.Errorf("Stream error: %v", err)
} else {
counter++
}
}
if counter == 0 {
t.Error("Stream did not return any responses")
}

_, err = c.CreateChatCompletion(
context.Background(),
openai.ChatCompletionRequest{
Expand Down Expand Up @@ -134,6 +109,41 @@ func TestAPI(t *testing.T) {
checks.NoError(t, err, "CreateChatCompletion (with functions) returned error")
}

func TestCompletionStream(t *testing.T) {
apiToken := os.Getenv("OPENAI_TOKEN")
if apiToken == "" {
t.Skip("Skipping testing against production OpenAI API. Set OPENAI_TOKEN environment variable to enable it.")
}

c := openai.NewClient(apiToken)
ctx := context.Background()

stream, err := c.CreateCompletionStream(ctx, openai.CompletionRequest{
Prompt: "Ex falso quodlibet",
Model: openai.GPT3Babbage002,
MaxTokens: 5,
Stream: true,
})
checks.NoError(t, err, "CreateCompletionStream returned error")
defer stream.Close()

counter := 0
for {
_, err = stream.Recv()
if err != nil {
if errors.Is(err, io.EOF) {
break
}
t.Errorf("Stream error: %v", err)
} else {
counter++
}
}
if counter == 0 {
t.Error("Stream did not return any responses")
}
}

func TestAPIError(t *testing.T) {
apiToken := os.Getenv("OPENAI_TOKEN")
if apiToken == "" {
Expand Down
31 changes: 17 additions & 14 deletions completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,33 @@ const (
GPT3Dot5Turbo16K0613 = "gpt-3.5-turbo-16k-0613"
GPT3Dot5Turbo = "gpt-3.5-turbo"
GPT3Dot5TurboInstruct = "gpt-3.5-turbo-instruct"
// Deprecated: Will be shut down on January 04, 2024. Use gpt-3.5-turbo-instruct instead.
// Deprecated: Model is shutdown. Use gpt-3.5-turbo-instruct instead.
GPT3TextDavinci003 = "text-davinci-003"
// Deprecated: Will be shut down on January 04, 2024. Use gpt-3.5-turbo-instruct instead.
// Deprecated: Model is shutdown. Use gpt-3.5-turbo-instruct instead.
GPT3TextDavinci002 = "text-davinci-002"
// Deprecated: Will be shut down on January 04, 2024. Use gpt-3.5-turbo-instruct instead.
// Deprecated: Model is shutdown. Use gpt-3.5-turbo-instruct instead.
GPT3TextCurie001 = "text-curie-001"
// Deprecated: Will be shut down on January 04, 2024. Use gpt-3.5-turbo-instruct instead.
// Deprecated: Model is shutdown. Use gpt-3.5-turbo-instruct instead.
GPT3TextBabbage001 = "text-babbage-001"
// Deprecated: Will be shut down on January 04, 2024. Use gpt-3.5-turbo-instruct instead.
// Deprecated: Model is shutdown. Use gpt-3.5-turbo-instruct instead.
GPT3TextAda001 = "text-ada-001"
// Deprecated: Will be shut down on January 04, 2024. Use gpt-3.5-turbo-instruct instead.
// Deprecated: Model is shutdown. Use gpt-3.5-turbo-instruct instead.
GPT3TextDavinci001 = "text-davinci-001"
// Deprecated: Will be shut down on January 04, 2024. Use gpt-3.5-turbo-instruct instead.
// Deprecated: Model is shutdown. Use gpt-3.5-turbo-instruct instead.
GPT3DavinciInstructBeta = "davinci-instruct-beta"
GPT3Davinci = "davinci"
GPT3Davinci002 = "davinci-002"
// Deprecated: Will be shut down on January 04, 2024. Use gpt-3.5-turbo-instruct instead.
// Deprecated: Model is shutdown. Use davinci-002 instead.
GPT3Davinci = "davinci"
GPT3Davinci002 = "davinci-002"
// Deprecated: Model is shutdown. Use gpt-3.5-turbo-instruct instead.
GPT3CurieInstructBeta = "curie-instruct-beta"
GPT3Curie = "curie"
GPT3Curie002 = "curie-002"
GPT3Ada = "ada"
GPT3Ada002 = "ada-002"
GPT3Babbage = "babbage"
GPT3Babbage002 = "babbage-002"
// Deprecated: Model is shutdown. Use babbage-002 instead.
GPT3Ada = "ada"
GPT3Ada002 = "ada-002"
// Deprecated: Model is shutdown. Use babbage-002 instead.
GPT3Babbage = "babbage"
GPT3Babbage002 = "babbage-002"
)

// Codex Defines the models provided by OpenAI.
Expand Down
2 changes: 1 addition & 1 deletion embeddings.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var ErrVectorLengthMismatch = errors.New("vector length mismatch")
type EmbeddingModel string

const (
// Deprecated: The following block will be shut down on January 04, 2024. Use text-embedding-ada-002 instead.
// Deprecated: The following block is shut down. Use text-embedding-ada-002 instead.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO these should just be removed now that they are shutdown, but wasn't sure that would cause issues

AdaSimilarity EmbeddingModel = "text-similarity-ada-001"
BabbageSimilarity EmbeddingModel = "text-similarity-babbage-001"
CurieSimilarity EmbeddingModel = "text-similarity-curie-001"
Expand Down
7 changes: 7 additions & 0 deletions internal/test/checks/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ func NoError(t *testing.T, err error, message ...string) {
}
}

func NoErrorF(t *testing.T, err error, message ...string) {
t.Helper()
if err != nil {
t.Fatal(err, message)
}
}

func HasError(t *testing.T, err error, message ...string) {
t.Helper()
if err == nil {
Expand Down
Loading