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

Use customRequireNoError for all ChatCompletions calls #23998

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
13 changes: 6 additions & 7 deletions sdk/ai/azopenai/client_chat_completions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ func TestClient_GetChatCompletions(t *testing.T) {
}

resp, err := client.GetChatCompletions(context.Background(), newTestChatCompletionOptions(deployment), nil)
skipNowIfThrottled(t, err)
require.NoError(t, err)
customRequireNoError(t, err, true)

require.NotEmpty(t, resp.ID)
require.NotEmpty(t, resp.Created)
Expand Down Expand Up @@ -173,7 +172,7 @@ func TestClient_GetChatCompletions_LogProbs(t *testing.T) {
}

resp, err := client.GetChatCompletions(context.Background(), opts, nil)
require.NoError(t, err)
customRequireNoError(t, err, true)

for _, choice := range resp.Choices {
require.NotEmpty(t, choice.LogProbs)
Expand Down Expand Up @@ -221,7 +220,7 @@ func TestClient_GetChatCompletions_LogitBias(t *testing.T) {
}

resp, err := client.GetChatCompletions(context.Background(), opts, nil)
require.NoError(t, err)
customRequireNoError(t, err, true)

for _, choice := range resp.Choices {
if choice.Message == nil || choice.Message.Content == nil {
Expand Down Expand Up @@ -394,7 +393,7 @@ func TestGetChatCompletions_usingResponseFormatForJSON(t *testing.T) {
}

resp, err := chatClient.GetChatCompletions(context.Background(), body, nil)
require.NoError(t, err)
customRequireNoError(t, err, true)

// validate that it came back as JSON data
var v any
Expand Down Expand Up @@ -536,7 +535,7 @@ func TestGetChatCompletions_StructuredOutputs(t *testing.T) {
},
},
}, nil)
require.NoError(t, err)
customRequireNoError(t, err, true)

// and now the results should contain proper JSON for the arguments, every time.
fn := resp.Choices[0].Message.ToolCalls[0].(*azopenai.ChatCompletionsFunctionToolCall).Function
Expand Down Expand Up @@ -619,7 +618,7 @@ func TestGetChatCompletions_StructuredOutputsResponseFormat(t *testing.T) {
},
},
}, nil)
require.NoError(t, err)
customRequireNoError(t, err, true)

jsonText := *resp.Choices[0].Message.Content

Expand Down
3 changes: 1 addition & 2 deletions sdk/ai/azopenai/client_completions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ func TestClient_GetCompletions(t *testing.T) {
Temperature: to.Ptr(float32(0.0)),
DeploymentName: &epm.Model,
}, nil)
skipNowIfThrottled(t, err)
require.NoError(t, err)
customRequireNoError(t, err, true)

// we'll do a general check here - as models change the answers can also change, token usages are different,
// etc... So we'll just make sure data is coming back and is reasonable.
Expand Down
4 changes: 2 additions & 2 deletions sdk/ai/azopenai/client_functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestGetChatCompletions_usingFunctions(t *testing.T) {
}

resp, err := chatClient.GetChatCompletions(context.Background(), body, nil)
require.NoError(t, err)
customRequireNoError(t, err, true)

funcCall := resp.Choices[0].Message.ToolCalls[0].(*azopenai.ChatCompletionsFunctionToolCall).Function

Expand Down Expand Up @@ -166,7 +166,7 @@ func TestGetChatCompletions_usingFunctions_legacy(t *testing.T) {
}

resp, err := client.GetChatCompletions(context.Background(), body, nil)
require.NoError(t, err)
customRequireNoError(t, err, true)

funcCall := resp.ChatCompletions.Choices[0].Message.FunctionCall

Expand Down
6 changes: 0 additions & 6 deletions sdk/ai/azopenai/client_shared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,6 @@ func getEndpoint(ev string, azure bool) string {
return v
}

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

type mimeTypeRecordingPolicy struct{}

// Do changes out the boundary for a multipart message. This makes it simpler to write
Expand Down
3 changes: 1 addition & 2 deletions sdk/ai/azopenai/custom_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ func TestGetCompletionsStream(t *testing.T) {
client := newTestClient(t, epm.Endpoint)

response, err := client.GetCompletionsStream(context.TODO(), body, nil)
skipNowIfThrottled(t, err)
require.NoError(t, err)
customRequireNoError(t, err, true)

if err != nil {
t.Errorf("Client.GetCompletionsStream() error = %v", err)
Expand Down
Loading