Compatible with the 2023-07-01-preview API interface of Azure Openai, when content interception is triggered, the error message will contain innererror (#460)

* Compatible with Azure Openai's 2023-07-01-preview version API interface about the error information returned by the intercepted interface

* Compatible with the 2023-07-01-preview API interface of Azure Openai, when content interception is triggered, the error message will contain innererror.InnerError struct is only valid for Azure OpenAI Service.
This commit is contained in:
ZeroDeng
2023-08-09 12:05:39 +08:00
committed by GitHub
parent 71a24931db
commit 34569895f6
2 changed files with 98 additions and 5 deletions

View File

@@ -7,12 +7,20 @@ 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"`
Param *string `json:"param,omitempty"`
Type string `json:"type"`
HTTPStatusCode int `json:"-"`
Code any `json:"code,omitempty"`
Message string `json:"message"`
Param *string `json:"param,omitempty"`
Type string `json:"type"`
HTTPStatusCode int `json:"-"`
InnerError *InnerError `json:"innererror,omitempty"`
}
// 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"`
}
// RequestError provides informations about generic request errors.
@@ -61,6 +69,13 @@ func (e *APIError) UnmarshalJSON(data []byte) (err error) {
}
}
if _, ok := rawMap["innererror"]; ok {
err = json.Unmarshal(rawMap["innererror"], &e.InnerError)
if err != nil {
return
}
}
// optional fields
if _, ok := rawMap["param"]; ok {
err = json.Unmarshal(rawMap["param"], &e.Param)