support for parsing error response message fields even if they are arrays (#381) (#384)

This commit is contained in:
渡邉祐一 / Yuichi Watanabe
2023-06-17 22:57:29 +09:00
committed by GitHub
parent f0770cfe1d
commit e49d771fff
2 changed files with 111 additions and 8 deletions

View File

@@ -3,6 +3,7 @@ package openai
import (
"encoding/json"
"fmt"
"strings"
)
// APIError provides error information returned by the OpenAI API.
@@ -41,7 +42,14 @@ func (e *APIError) UnmarshalJSON(data []byte) (err error) {
err = json.Unmarshal(rawMap["message"], &e.Message)
if err != nil {
return
// If the parameter field of a function call is invalid as a JSON schema
// refs: https://github.com/sashabaranov/go-openai/issues/381
var messages []string
err = json.Unmarshal(rawMap["message"], &messages)
if err != nil {
return
}
e.Message = strings.Join(messages, ", ")
}
// optional fields for azure openai