Skip to content

Commit

Permalink
Compatible with the 2023-07-01-preview API interface of Azure Openai,…
Browse files Browse the repository at this point in the history
… when content interception is triggered, the error message will contain innererror.InnerError struct is only valid for Azure OpenAI Service.
  • Loading branch information
ZeroDeng01 committed Aug 8, 2023
1 parent 950d61b commit becb741
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion error.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
)

// APIError provides error information returned by the OpenAI API.
// InnerError struct is only valid for Azure OpenAI Service.
type APIError struct {
Code any `json:"code,omitempty"`
Message string `json:"message"`
Expand All @@ -16,7 +17,7 @@ type APIError struct {
InnerError InnerError `json:"innererror,omitempty"`
}

// InnerError Azure Content filtering.
// InnerError Azure Content filtering. Only valid for Azure OpenAI Service.
type InnerError struct {
Code string `json:"code,omitempty"`
ContentFilterResults ContentFilterResults `json:"content_filter_result,omitempty"`
Expand Down
10 changes: 9 additions & 1 deletion error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,21 @@ func TestAPIErrorUnmarshalJSON(t *testing.T) {
},
},
{
name: "parse succeeds when the innerError is exists (Azure Openai)",
name: "parse succeeds when the innerError is not exists (Azure Openai)",
response: `{"message": "","type": null,"param": "","code": "","status": 0,"innererror": {}}`,
hasError: false,
checkFunc: func(t *testing.T, apiErr APIError) {
assertAPIErrorInnerError(t, apiErr, InnerError{})
},
},
{
name: "parse succeeds when the innerError is not InnerError struct (Azure Openai)",
response: `{"message": "","type": null,"param": "","code": "","status": 0,"innererror": "test"}`,
hasError: true,
checkFunc: func(t *testing.T, apiErr APIError) {
assertAPIErrorInnerError(t, apiErr, InnerError{})
},
},
{
name: "parse failed when the message is object",
response: `{"message":{},"type":"invalid_request_error","param":null,"code":null}`,
Expand Down

0 comments on commit becb741

Please sign in to comment.