mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-19 07:27:43 +08:00
Tighten XML tool call parsing and upstream empty handling
This commit is contained in:
@@ -117,7 +117,7 @@ func BuildResponsesFunctionCallArgumentsDonePayload(responseID, itemID string, o
|
||||
}
|
||||
}
|
||||
|
||||
func BuildResponsesFailedPayload(responseID, model, message, code string) map[string]any {
|
||||
func BuildResponsesFailedPayload(responseID, model string, status int, message, code string) map[string]any {
|
||||
code = strings.TrimSpace(code)
|
||||
if code == "" {
|
||||
code = "api_error"
|
||||
@@ -129,15 +129,36 @@ func BuildResponsesFailedPayload(responseID, model, message, code string) map[st
|
||||
"object": "response",
|
||||
"model": model,
|
||||
"status": "failed",
|
||||
"status_code": status,
|
||||
"error": map[string]any{
|
||||
"message": message,
|
||||
"type": "invalid_request_error",
|
||||
"type": responsesErrorType(status),
|
||||
"code": code,
|
||||
"param": nil,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func responsesErrorType(status int) string {
|
||||
switch status {
|
||||
case 400, 404, 422:
|
||||
return "invalid_request_error"
|
||||
case 401:
|
||||
return "authentication_error"
|
||||
case 403:
|
||||
return "permission_error"
|
||||
case 429:
|
||||
return "rate_limit_error"
|
||||
case 503:
|
||||
return "service_unavailable_error"
|
||||
default:
|
||||
if status >= 500 {
|
||||
return "api_error"
|
||||
}
|
||||
return "invalid_request_error"
|
||||
}
|
||||
}
|
||||
|
||||
func BuildResponsesCompletedPayload(response map[string]any) map[string]any {
|
||||
responseID, _ := response["id"].(string)
|
||||
return map[string]any{
|
||||
|
||||
Reference in New Issue
Block a user