feat: configure native messages model matching

This commit is contained in:
Seefs
2026-04-26 13:37:59 +08:00
parent f2f3410dcf
commit 62d4b63fc3
+21 -2
View File
@@ -7,6 +7,7 @@ import (
"net/http"
"strings"
"github.com/QuantumNous/new-api/common"
"github.com/QuantumNous/new-api/dto"
"github.com/QuantumNous/new-api/relay/channel"
"github.com/QuantumNous/new-api/relay/channel/claude"
@@ -18,12 +19,16 @@ import (
"github.com/QuantumNous/new-api/types"
"github.com/gin-gonic/gin"
"github.com/samber/lo"
)
type Adaptor struct {
IsSyncImageModel bool
}
const aliAnthropicMessagesModelsEnv = "ALI_ANTHROPIC_MESSAGES_MODELS"
const defaultAliAnthropicMessagesModels = "qwen,deepseek-v4,kimi,glm,minimax-m"
/*
var syncModels = []string{
"z-image",
@@ -32,8 +37,22 @@ type Adaptor struct {
}
*/
func supportsAliAnthropicMessages(modelName string) bool {
// Only models with the "qwen" designation can use the Claude-compatible interface; others require conversion.
return strings.Contains(strings.ToLower(modelName), "qwen")
normalizedModelName := strings.ToLower(strings.TrimSpace(modelName))
if normalizedModelName == "" {
return false
}
return lo.SomeBy(aliAnthropicMessagesModelPatterns(), func(pattern string) bool {
return strings.Contains(normalizedModelName, pattern)
})
}
func aliAnthropicMessagesModelPatterns() []string {
configuredModels := common.GetEnvOrDefaultString(aliAnthropicMessagesModelsEnv, defaultAliAnthropicMessagesModels)
return lo.FilterMap(strings.Split(configuredModels, ","), func(item string, _ int) (string, bool) {
pattern := strings.ToLower(strings.TrimSpace(item))
return pattern, pattern != ""
})
}
var syncModels = []string{