diff --git a/sdk/ai/azopenai/CHANGELOG.md b/sdk/ai/azopenai/CHANGELOG.md index dc2f97a3cead..4cfb7fe91743 100644 --- a/sdk/ai/azopenai/CHANGELOG.md +++ b/sdk/ai/azopenai/CHANGELOG.md @@ -1,6 +1,6 @@ # Release History -## 0.3.0 (Unreleased) +## 0.3.0 (2023-09-26) ### Features Added - Support for Whisper audio APIs for transcription and translation using `GetAudioTranscription` and `GetAudioTranslation`. @@ -9,10 +9,6 @@ - ChatChoiceContentFilterResults content filtering fields are now all typed as ContentFilterResult, instead of unique types for each field. - `PromptAnnotations` renamed to `PromptFilterResults` in `ChatCompletions` and `Completions`. -### Bugs Fixed - -### Other Changes - ## 0.2.0 (2023-08-28) ### Features Added diff --git a/sdk/ai/azopenai/autorest.md b/sdk/ai/azopenai/autorest.md index 9ebcfbc58157..00af5456e2d2 100644 --- a/sdk/ai/azopenai/autorest.md +++ b/sdk/ai/azopenai/autorest.md @@ -201,6 +201,17 @@ directive: fix($.AudioTranslationOptions.properties.response_format); fix($.AudioTranslation.properties.task); + + - from: + - options.go + - models_serde.go + - models.go + where: $ + transform: | + return $ + .replace(/AvgLogprob \*float32/g, "AvgLogProb *float32") + .replace(/(a|c)\.AvgLogprob/g, "$1.AvgLogProb") + # # [END] Whisper # @@ -253,10 +264,16 @@ directive: where: $ transform: | return $ - // InnerError is actually a recursive type, no need for this innererrorinnererror type + // remove some types that were generated to support the recursive error. .replace(/\/\/ AzureCoreFoundationsInnerErrorInnererror.+?\n}/s, "") // also, remove its marshalling functions - .replace(/\/\/ (Unmarshal|Marshal)JSON implements[^\n]+?AzureCoreFoundationsInnerErrorInnererror.+?\n}/sg, "") + .replace(/\/\/ (Unmarshal|Marshal)JSON implements[^\n]+?for type AzureCoreFoundationsInnerErrorInnererror.+?\n}/sg, "") + .replace(/\/\/ AzureCoreFoundationsErrorInnererror.+?\n}/s, "") + .replace(/\/\/ (Unmarshal|Marshal)JSON implements[^\n]+?for type AzureCoreFoundationsErrorInnererror.+?\n}/sg, "") + .replace(/\/\/ AzureCoreFoundationsErrorResponseError.+?\n}/s, "") + .replace(/\/\/ (Unmarshal|Marshal)JSON implements[^\n]+?for type AzureCoreFoundationsErrorResponseError.+?\n}/sg, "") + .replace(/\/\/ AzureCoreFoundationsErrorResponse.+?\n}/s, "") + .replace(/\/\/ (Unmarshal|Marshal)JSON implements[^\n]+?for type AzureCoreFoundationsErrorResponse.+?\n}/sg, "") // Remove any references to the type and replace them with InnerError. .replace(/Innererror \*(AzureCoreFoundationsInnerErrorInnererror|AzureCoreFoundationsErrorInnererror)/g, "InnerError *InnerError") diff --git a/sdk/ai/azopenai/client_chat_completions_test.go b/sdk/ai/azopenai/client_chat_completions_test.go index 6ae87db95221..5f7fe66bf3f0 100644 --- a/sdk/ai/azopenai/client_chat_completions_test.go +++ b/sdk/ai/azopenai/client_chat_completions_test.go @@ -10,6 +10,7 @@ import ( "context" "errors" "io" + "net/http" "os" "testing" @@ -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 { @@ -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 diff --git a/sdk/ai/azopenai/models.go b/sdk/ai/azopenai/models.go index 2c1557e73150..ad5ae38e29d9 100644 --- a/sdk/ai/azopenai/models.go +++ b/sdk/ai/azopenai/models.go @@ -61,7 +61,7 @@ type AudioTranscriptionOptions struct { // sentences. type AudioTranscriptionSegment struct { // REQUIRED; The average log probability associated with this audio segment. - AvgLogprob *float32 + AvgLogProb *float32 // REQUIRED; The compression ratio of this audio segment. CompressionRatio *float32 @@ -140,7 +140,7 @@ type AudioTranslationOptions struct { // sentences. type AudioTranslationSegment struct { // REQUIRED; The average log probability associated with this audio segment. - AvgLogprob *float32 + AvgLogProb *float32 // REQUIRED; The compression ratio of this audio segment. CompressionRatio *float32 @@ -298,40 +298,6 @@ type Error struct { Target *string } -// ErrorInnererror - An object containing more specific information than the current object about the -// error. -type ErrorInnererror struct { - // One of a server-defined set of error codes. - Code *string - - // Inner error. - InnerError *InnerError -} - -// ErrorResponse - A response containing error details. -type ErrorResponse struct { - // REQUIRED; The error object. - Error *ErrorResponseError -} - -// ErrorResponseError - The error object. -type ErrorResponseError struct { - // REQUIRED; One of a server-defined set of error codes. - Code *string - - // REQUIRED; A human-readable representation of the error. - Message *string - - // An array of details about specific errors that led to this reported error. - Details []Error - - // An object containing more specific information than the current object about the error. - InnerError *InnerError - - // The target of the error. - Target *string -} - // InnerError - An object containing more specific information about the error. As per Microsoft One API // guidelines - // https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses. diff --git a/sdk/ai/azopenai/models_serde.go b/sdk/ai/azopenai/models_serde.go index 8fad187ff4f4..d0edd14b26e5 100644 --- a/sdk/ai/azopenai/models_serde.go +++ b/sdk/ai/azopenai/models_serde.go @@ -110,7 +110,7 @@ func (a *AudioTranscriptionOptions) UnmarshalJSON(data []byte) error { // MarshalJSON implements the json.Marshaller interface for type AudioTranscriptionSegment. func (a AudioTranscriptionSegment) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) - populate(objectMap, "avg_logprob", a.AvgLogprob) + populate(objectMap, "avg_logprob", a.AvgLogProb) populate(objectMap, "compression_ratio", a.CompressionRatio) populate(objectMap, "end", a.End) populate(objectMap, "id", a.ID) @@ -133,7 +133,7 @@ func (a *AudioTranscriptionSegment) UnmarshalJSON(data []byte) error { var err error switch key { case "avg_logprob": - err = unpopulate(val, "AvgLogprob", &a.AvgLogprob) + err = unpopulate(val, "AvgLogprob", &a.AvgLogProb) delete(rawMsg, key) case "compression_ratio": err = unpopulate(val, "CompressionRatio", &a.CompressionRatio) @@ -259,7 +259,7 @@ func (a *AudioTranslationOptions) UnmarshalJSON(data []byte) error { // MarshalJSON implements the json.Marshaller interface for type AudioTranslationSegment. func (a AudioTranslationSegment) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) - populate(objectMap, "avg_logprob", a.AvgLogprob) + populate(objectMap, "avg_logprob", a.AvgLogProb) populate(objectMap, "compression_ratio", a.CompressionRatio) populate(objectMap, "end", a.End) populate(objectMap, "id", a.ID) @@ -282,7 +282,7 @@ func (a *AudioTranslationSegment) UnmarshalJSON(data []byte) error { var err error switch key { case "avg_logprob": - err = unpopulate(val, "AvgLogprob", &a.AvgLogprob) + err = unpopulate(val, "AvgLogprob", &a.AvgLogProb) delete(rawMsg, key) case "compression_ratio": err = unpopulate(val, "CompressionRatio", &a.CompressionRatio) @@ -581,107 +581,6 @@ func (a *Error) UnmarshalJSON(data []byte) error { return nil } -// MarshalJSON implements the json.Marshaller interface for type ErrorInnererror. -func (a ErrorInnererror) MarshalJSON() ([]byte, error) { - objectMap := make(map[string]any) - populate(objectMap, "code", a.Code) - populate(objectMap, "innererror", a.InnerError) - return json.Marshal(objectMap) -} - -// UnmarshalJSON implements the json.Unmarshaller interface for type ErrorInnererror. -func (a *ErrorInnererror) UnmarshalJSON(data []byte) error { - var rawMsg map[string]json.RawMessage - if err := json.Unmarshal(data, &rawMsg); err != nil { - return fmt.Errorf("unmarshalling type %T: %v", a, err) - } - for key, val := range rawMsg { - var err error - switch key { - case "code": - err = unpopulate(val, "Code", &a.Code) - delete(rawMsg, key) - case "innererror": - err = unpopulate(val, "Innererror", &a.InnerError) - delete(rawMsg, key) - } - if err != nil { - return fmt.Errorf("unmarshalling type %T: %v", a, err) - } - } - return nil -} - -// MarshalJSON implements the json.Marshaller interface for type ErrorResponse. -func (a ErrorResponse) MarshalJSON() ([]byte, error) { - objectMap := make(map[string]any) - populate(objectMap, "error", a.Error) - return json.Marshal(objectMap) -} - -// UnmarshalJSON implements the json.Unmarshaller interface for type ErrorResponse. -func (a *ErrorResponse) UnmarshalJSON(data []byte) error { - var rawMsg map[string]json.RawMessage - if err := json.Unmarshal(data, &rawMsg); err != nil { - return fmt.Errorf("unmarshalling type %T: %v", a, err) - } - for key, val := range rawMsg { - var err error - switch key { - case "error": - err = unpopulate(val, "Error", &a.Error) - delete(rawMsg, key) - } - if err != nil { - return fmt.Errorf("unmarshalling type %T: %v", a, err) - } - } - return nil -} - -// MarshalJSON implements the json.Marshaller interface for type ErrorResponseError. -func (a ErrorResponseError) MarshalJSON() ([]byte, error) { - objectMap := make(map[string]any) - populate(objectMap, "code", a.Code) - populate(objectMap, "details", a.Details) - populate(objectMap, "innererror", a.InnerError) - populate(objectMap, "message", a.Message) - populate(objectMap, "target", a.Target) - return json.Marshal(objectMap) -} - -// UnmarshalJSON implements the json.Unmarshaller interface for type ErrorResponseError. -func (a *ErrorResponseError) UnmarshalJSON(data []byte) error { - var rawMsg map[string]json.RawMessage - if err := json.Unmarshal(data, &rawMsg); err != nil { - return fmt.Errorf("unmarshalling type %T: %v", a, err) - } - for key, val := range rawMsg { - var err error - switch key { - case "code": - err = unpopulate(val, "Code", &a.Code) - delete(rawMsg, key) - case "details": - err = unpopulate(val, "Details", &a.Details) - delete(rawMsg, key) - case "innererror": - err = unpopulate(val, "Innererror", &a.InnerError) - delete(rawMsg, key) - case "message": - err = unpopulate(val, "Message", &a.Message) - delete(rawMsg, key) - case "target": - err = unpopulate(val, "Target", &a.Target) - delete(rawMsg, key) - } - if err != nil { - return fmt.Errorf("unmarshalling type %T: %v", a, err) - } - } - return nil -} - // MarshalJSON implements the json.Marshaller interface for type InnerError. func (a InnerError) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any)