feat(platform): 开源发布 - 初始化 Open AI Canvas
This commit is contained in:
commit
aea35896eb
365 files changed
+66410
No files matched your search
@@ -0,0 +1,64 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const contentModerationErrorCode = "sensitive_words_detected"
|
||||
|
||||
const contentModerationRetryMessage = "内容审核未通过,请修改提示词后重新生成;原任务不能直接重试"
|
||||
|
||||
// 只提取供应商明确返回的错误码和短消息,避免把完整响应或用户输入复制到调用日志。
|
||||
func providerFailureDetails(payload map[string]any) (string, string) {
|
||||
candidates := make([]map[string]any, 0, 3)
|
||||
for _, key := range []string{"error", "data"} {
|
||||
if nested, ok := payload[key].(map[string]any); ok {
|
||||
candidates = append(candidates, nested)
|
||||
}
|
||||
}
|
||||
// 内层通常是供应商业务错误,外层 code 可能只是 HTTP 包装码。
|
||||
candidates = append(candidates, payload)
|
||||
code := ""
|
||||
message := ""
|
||||
for _, candidate := range candidates {
|
||||
if code == "" {
|
||||
code = normalizedProviderErrorCode(candidate["code"])
|
||||
}
|
||||
if message == "" {
|
||||
message = strings.TrimSpace(stringField(candidate, "message"))
|
||||
}
|
||||
}
|
||||
return code, truncateRunes(message, 500)
|
||||
}
|
||||
|
||||
func normalizedProviderErrorCode(value any) string {
|
||||
var code string
|
||||
switch current := value.(type) {
|
||||
case string:
|
||||
code = current
|
||||
case fmt.Stringer:
|
||||
code = current.String()
|
||||
case float64:
|
||||
if current != 0 {
|
||||
code = fmt.Sprintf("%g", current)
|
||||
}
|
||||
case int:
|
||||
if current != 0 {
|
||||
code = fmt.Sprintf("%d", current)
|
||||
}
|
||||
case int64:
|
||||
if current != 0 {
|
||||
code = fmt.Sprintf("%d", current)
|
||||
}
|
||||
}
|
||||
code = strings.TrimSpace(code)
|
||||
if code == "0" {
|
||||
return ""
|
||||
}
|
||||
return truncateRunes(code, 80)
|
||||
}
|
||||
|
||||
func isContentModerationFailure(value string) bool {
|
||||
return strings.Contains(strings.ToLower(value), contentModerationErrorCode)
|
||||
}
|
||||
Reference in new issue
Block a user