198 lines
8.6 KiB
Go
198 lines
8.6 KiB
Go
package providers
|
|
|
|
import "strings"
|
|
|
|
// FailureMessage returns a user-facing reason for a confirmed provider rejection
|
|
// or a failed asynchronous task. The code must come from the named provider;
|
|
// provider response prose must never be passed through to the user.
|
|
//
|
|
// Error-code references:
|
|
// Volcengine Ark: https://docs.volcengine.com/docs/82379/1299023
|
|
// Bailian: https://help.aliyun.com/zh/model-studio/error-code/
|
|
// EvoLink API codes: https://evolink.ai/zh/blog/wan-2-7-api-guide
|
|
// Jimeng visual codes: https://docs.volcengine.com/docs/AIGCAIzhongtaigongyongwendang/69728
|
|
// and https://www.volcengine.com/docs/85621/1791184
|
|
func FailureMessage(provider string, status int, code string) string {
|
|
code = strings.TrimSpace(code)
|
|
switch strings.ToLower(strings.TrimSpace(provider)) {
|
|
case "seedance", "seedream":
|
|
if message := arkFailureMessage(code); message != "" {
|
|
return message
|
|
}
|
|
case "minimax":
|
|
if message := minimaxFailureMessage(code); message != "" {
|
|
return message
|
|
}
|
|
case "bailian":
|
|
if message := bailianFailureMessage(code); message != "" {
|
|
return message
|
|
}
|
|
case "evolink":
|
|
if message := evolinkFailureMessage(code); message != "" {
|
|
return message
|
|
}
|
|
case "volcengine-visual":
|
|
if message := jimengFailureMessage(code); message != "" {
|
|
return message
|
|
}
|
|
}
|
|
return failureMessageForStatus(status)
|
|
}
|
|
|
|
func arkFailureMessage(code string) string {
|
|
if code == "InputImageSensitiveContentDetected.PrivacyInformation" {
|
|
return "参考图片可能包含真人,未通过服务商审核;请更换符合要求的图片后重试。"
|
|
}
|
|
if code == "InputVideoSensitiveContentDetected.PrivacyInformation" {
|
|
return "参考视频可能包含真人,未通过服务商审核;请更换符合要求的视频后重试。"
|
|
}
|
|
for _, item := range []struct{ code, material string }{
|
|
{"InputTextSensitiveContentDetected", "提示词"},
|
|
{"InputImageSensitiveContentDetected", "参考图片"},
|
|
{"InputVideoSensitiveContentDetected", "参考视频"},
|
|
{"InputAudioSensitiveContentDetected", "参考音频"},
|
|
{"OutputTextSensitiveContentDetected", "生成的文字"},
|
|
{"OutputImageSensitiveContentDetected", "生成的图片"},
|
|
{"OutputVideoSensitiveContentDetected", "生成的视频"},
|
|
{"OutputAudioSensitiveContentDetected", "生成的音频"},
|
|
} {
|
|
if code == item.code+".PolicyViolation" {
|
|
return item.material + "可能涉及版权限制,请调整内容后重试。"
|
|
}
|
|
if code == item.code || strings.HasPrefix(code, item.code+".") {
|
|
return item.material + "未通过服务商内容审核,请调整内容后重试。"
|
|
}
|
|
}
|
|
switch code {
|
|
case "InvalidImageURL.EmptyURL", "InvalidImageURL.InvalidFormat", "InvalidParameter.TosURLInvalid":
|
|
return "参考图片无法读取,请重新上传图片后重试。"
|
|
case "OperationDenied.ServiceNotOpen", "OperationDenied.PermissionDenied":
|
|
return "当前模型服务尚未开通或无权使用,请联系管理员处理。"
|
|
case "OperationDenied.ServiceOverdue":
|
|
return "生成服务账户已逾期,请联系管理员处理。"
|
|
case "InvalidAccountStatus":
|
|
return "生成服务账户状态异常,请联系管理员处理。"
|
|
case "ContentSecurityDetectionError":
|
|
return "服务商内容审核暂时不可用,请稍后重试。"
|
|
}
|
|
if code == "MissingParameter" || strings.HasPrefix(code, "MissingParameter.") || code == "InvalidParameter" || strings.HasPrefix(code, "InvalidParameter.") {
|
|
return "当前生成参数不符合模型要求,请调整设置或切换模型后重试。"
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func minimaxFailureMessage(code string) string {
|
|
switch code {
|
|
case "1002":
|
|
return "MiniMax 请求过于频繁,请稍后重试。"
|
|
case "1004", "2049":
|
|
return "MiniMax 服务凭证无效,请联系管理员处理。"
|
|
case "1008":
|
|
return "MiniMax 生成服务账户余额不足,请联系管理员处理。"
|
|
case "1026":
|
|
return "视频描述或参考素材未通过 MiniMax 内容审核,请调整后重试。"
|
|
case "2013":
|
|
return "当前生成参数不符合 MiniMax 模型要求,请调整设置后重试。"
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func bailianFailureMessage(code string) string {
|
|
switch code {
|
|
case "Arrearage", "isv.OUT_OF_SERVICE":
|
|
return "百炼生成服务账户余额不足或逾期,请联系管理员处理。"
|
|
case "DataInspectionFailed", "data_inspection_failed":
|
|
return "输入或生成内容未通过百炼审核,请调整提示词或素材后重试。"
|
|
case "IPInfringementSuspect":
|
|
return "输入内容可能涉及知识产权限制,请调整提示词或素材后重试。"
|
|
case "InvalidParameter", "InternalError.Algo.InvalidParameter":
|
|
return "当前生成参数不符合百炼模型要求,请调整设置后重试。"
|
|
case "InvalidURL", "InvalidURL.ConnectionRefused", "InvalidURL.Timeout", "InvalidFile.DownloadFailed", "InvalidParameter.FileDownload":
|
|
return "参考素材无法下载,请重新上传可访问的素材后重试。"
|
|
case "InvalidParameter.DataInspection":
|
|
return "参考素材在安全审核时无法访问,请重新上传素材;若仍失败请联系管理员。"
|
|
case "InvalidFile.Size", "InvalidFile.Format", "InvalidFile.Resolution", "InvalidFile.FPS", "InvalidFile.Duration", "InvalidFile.ImageSize", "InvalidFile.Openerror":
|
|
return "参考素材的格式、大小或时长不符合模型要求,请更换素材后重试。"
|
|
case "InvalidApiKey", "AccessDenied", "Resource.AccessDenied", "Workspace.AccessDenied":
|
|
return "百炼生成服务鉴权或使用权限异常,请联系管理员处理。"
|
|
case "Throttling":
|
|
return "百炼请求过于频繁,请稍后重试。"
|
|
case "InternalError", "InternalError.Algo":
|
|
return "百炼生成服务暂时异常,请稍后重试。"
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func evolinkFailureMessage(code string) string {
|
|
switch code {
|
|
case "invalid_request":
|
|
return "当前生成参数不符合模型要求,请检查提示词、素材和设置后重试。"
|
|
case "unauthorized":
|
|
return "EvoLink 生成服务鉴权失败,请联系管理员处理。"
|
|
case "insufficient_quota":
|
|
return "EvoLink 生成服务账户额度不足,请联系管理员处理。"
|
|
case "model_access_denied":
|
|
return "当前 EvoLink 模型无调用权限,请联系管理员处理。"
|
|
case "rate_limit_exceeded":
|
|
return "EvoLink 请求频率过高,请稍后重试。"
|
|
case "internal_error":
|
|
return "EvoLink 生成服务暂时异常,请稍后重试。"
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func jimengFailureMessage(code string) string {
|
|
switch code {
|
|
case "50200", "50201", "50204":
|
|
return "当前生成参数不符合即梦模型要求,请调整设置后重试。"
|
|
case "50205", "50206", "50207":
|
|
return "参考图片过大、为空或无法读取,请更换图片后重试。"
|
|
case "50209", "50210", "50211", "50214":
|
|
return "参考视频的内容、大小或时长不符合要求,请更换视频后重试。"
|
|
case "50213":
|
|
return "提交的素材总大小超过即梦限制,请减少或压缩素材后重试。"
|
|
case "60102":
|
|
return "参考图片中未检测到人脸,请更换清晰的人像图片后重试。"
|
|
case "60208", "50411":
|
|
return "参考图片未通过即梦内容审核,请更换图片后重试。"
|
|
case "50511":
|
|
return "生成的图片未通过即梦内容审核,请调整提示词或素材后重试。"
|
|
case "50412", "50413":
|
|
return "提示词未通过即梦内容审核,请调整内容后重试。"
|
|
case "50512":
|
|
return "生成的文字未通过即梦内容审核,请调整提示词或素材后重试。"
|
|
case "50400":
|
|
return "即梦服务鉴权或调用权限异常,请联系管理员处理。"
|
|
case "50402":
|
|
return "即梦模型接口不可用,请联系管理员检查配置。"
|
|
case "50429", "50430":
|
|
return "即梦请求频率或并发达到上限,请稍后重试。"
|
|
case "50500", "50501":
|
|
return "即梦生成服务暂时异常,请稍后重试。"
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func failureMessageForStatus(status int) string {
|
|
switch status {
|
|
case 0:
|
|
return "服务商未能完成生成,请联系管理员查看错误详情。"
|
|
case 401:
|
|
return "生成服务鉴权失败,请联系管理员处理。"
|
|
case 402:
|
|
return "生成服务账户额度不足,请联系管理员处理。"
|
|
case 403:
|
|
return "当前生成服务无权使用,请联系管理员处理。"
|
|
case 404:
|
|
return "模型或生成任务不存在,请联系管理员检查配置。"
|
|
case 408, 504:
|
|
return "服务商请求超时,无法确认是否已接收,请联系管理员核查任务状态。"
|
|
case 429:
|
|
return "生成服务请求频率过高,请稍后重试。"
|
|
case 500, 502, 503:
|
|
return "生成服务暂时异常,请稍后重试。"
|
|
default:
|
|
return "服务商拒绝了本次请求,请联系管理员查看错误详情。"
|
|
}
|
|
}
|