Sfoglia il codice sorgente

feat: configure native messages model matching

Seefs 1 mese fa
parent
commit
62d4b63fc3
1 ha cambiato i file con 21 aggiunte e 2 eliminazioni
  1. 21 2
      relay/channel/ali/adaptor.go

+ 21 - 2
relay/channel/ali/adaptor.go

@@ -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{