feat: configure native messages model matching
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/QuantumNous/new-api/common"
|
||||||
"github.com/QuantumNous/new-api/dto"
|
"github.com/QuantumNous/new-api/dto"
|
||||||
"github.com/QuantumNous/new-api/relay/channel"
|
"github.com/QuantumNous/new-api/relay/channel"
|
||||||
"github.com/QuantumNous/new-api/relay/channel/claude"
|
"github.com/QuantumNous/new-api/relay/channel/claude"
|
||||||
@@ -18,12 +19,16 @@ import (
|
|||||||
"github.com/QuantumNous/new-api/types"
|
"github.com/QuantumNous/new-api/types"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/samber/lo"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Adaptor struct {
|
type Adaptor struct {
|
||||||
IsSyncImageModel bool
|
IsSyncImageModel bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const aliAnthropicMessagesModelsEnv = "ALI_ANTHROPIC_MESSAGES_MODELS"
|
||||||
|
const defaultAliAnthropicMessagesModels = "qwen,deepseek-v4,kimi,glm,minimax-m"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
var syncModels = []string{
|
var syncModels = []string{
|
||||||
"z-image",
|
"z-image",
|
||||||
@@ -32,8 +37,22 @@ type Adaptor struct {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
func supportsAliAnthropicMessages(modelName string) bool {
|
func supportsAliAnthropicMessages(modelName string) bool {
|
||||||
// Only models with the "qwen" designation can use the Claude-compatible interface; others require conversion.
|
normalizedModelName := strings.ToLower(strings.TrimSpace(modelName))
|
||||||
return strings.Contains(strings.ToLower(modelName), "qwen")
|
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{
|
var syncModels = []string{
|
||||||
|
|||||||
Reference in New Issue
Block a user