Skip to content

Commit

Permalink
Add skip logic if OpenAI is overloaded.
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Park committed Sep 26, 2023
1 parent 3f49132 commit 722171e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions sdk/ai/azopenai/client_chat_completions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"context"
"errors"
"io"
"net/http"
"os"
"testing"

Expand Down Expand Up @@ -89,6 +90,11 @@ func testGetChatCompletions(t *testing.T, client *azopenai.Client, tv testVars)
}

resp, err := client.GetChatCompletions(context.Background(), newTestChatCompletionOptions(tv), nil)

if respErr := (*azcore.ResponseError)(nil); errors.As(err, &respErr) && respErr.StatusCode == http.StatusTooManyRequests {
t.Skipf("OpenAI resource overloaded, skipping this test")
}

require.NoError(t, err)

if tv.Endpoint.Azure {
Expand All @@ -111,6 +117,11 @@ func testGetChatCompletions(t *testing.T, client *azopenai.Client, tv testVars)

func testGetChatCompletionsStream(t *testing.T, client *azopenai.Client, tv testVars) {
streamResp, err := client.GetChatCompletionsStream(context.Background(), newTestChatCompletionOptions(tv), nil)

if respErr := (*azcore.ResponseError)(nil); errors.As(err, &respErr) && respErr.StatusCode == http.StatusTooManyRequests {
t.Skipf("OpenAI resource overloaded, skipping this test")
}

require.NoError(t, err)

// the data comes back differently for streaming
Expand Down

0 comments on commit 722171e

Please sign in to comment.