Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions relay/channel/ali/adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/QuantumNous/new-api/relay/channel/openai"
relaycommon "github.com/QuantumNous/new-api/relay/common"
"github.com/QuantumNous/new-api/relay/constant"
"github.com/QuantumNous/new-api/setting/model_setting"
"github.com/QuantumNous/new-api/service"
"github.com/QuantumNous/new-api/types"

Expand All @@ -23,6 +24,13 @@ type Adaptor struct {
IsSyncImageModel bool
}

/*
var syncModels = []string{
"z-image",
"qwen-image",
"wan2.6",
}
*/
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")
Expand All @@ -35,12 +43,7 @@ var syncModels = []string{
}

func isSyncImageModel(modelName string) bool {
for _, m := range syncModels {
if strings.Contains(modelName, m) {
return true
}
}
return false
return model_setting.IsSyncImageModel(modelName)
}

func (a *Adaptor) ConvertGeminiRequest(*gin.Context, *relaycommon.RelayInfo, *dto.GeminiChatRequest) (any, error) {
Expand Down
50 changes: 50 additions & 0 deletions setting/model_setting/qwen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package model_setting

import (
"strings"

"github.com/QuantumNous/new-api/setting/config"
)

// QwenSettings defines Qwen model configuration. 注意bool要以enabled结尾才可以生效编辑
type QwenSettings struct {
SyncImageModels []string `json:"sync_image_models"`
}

// 默认配置
var defaultQwenSettings = QwenSettings{
SyncImageModels: []string{
"z-image",
"qwen-image",
"wan2.6",
"qwen-image-edit",
"qwen-image-edit-max",
"qwen-image-edit-max-2026-01-16",
"qwen-image-edit-plus",
"qwen-image-edit-plus-2025-12-15",
"qwen-image-edit-plus-2025-10-30",
},
}

// 全局实例
var qwenSettings = defaultQwenSettings

func init() {
// 注册到全局配置管理器
config.GlobalConfig.Register("qwen", &qwenSettings)
}

// GetQwenSettings
func GetQwenSettings() *QwenSettings {
return &qwenSettings
}

// IsSyncImageModel
func IsSyncImageModel(model string) bool {
for _, m := range qwenSettings.SyncImageModels {
if strings.Contains(model, m) {
return true
}
}
return false
Comment on lines +42 to +49

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find where IsSyncImageModel is called and check for model name normalization patterns
rg -n --type=go 'IsSyncImageModel\(' -A 2 -B 2

Repository: QuantumNous/new-api

Length of output: 639


🏁 Script executed:

#!/bin/bash
# Check for existing ToLower patterns with model-related variables
rg -n --type=go 'strings\.ToLower\([^)]*model' -i

Repository: QuantumNous/new-api

Length of output: 1035


🏁 Script executed:

#!/bin/bash
# Look for model name normalization patterns
rg -n --type=go 'OriginModelName|UpstreamModelName|model.*ToLower|ToLower.*model' -i

Repository: QuantumNous/new-api

Length of output: 26805


🏁 Script executed:

#!/bin/bash
# Check the qwen.go file to understand the SyncImageModels data
cat -n setting/model_setting/qwen.go | head -60

Repository: QuantumNous/new-api

Length of output: 1373


Use case-insensitive matching for model name comparison. The IsSyncImageModel function uses strings.Contains, which is case-sensitive. Since the codebase consistently normalizes model names to lowercase for comparisons (e.g., relay/channel/ali/adaptor.go:36, relay/channel/openai/relay-openai.go:127), and the config values are all lowercase, this function should follow the same pattern to handle mixed-case inputs from upstream sources or user config.

Suggested fix
 func IsSyncImageModel(model string) bool {
+	model = strings.ToLower(model)
 	for _, m := range qwenSettings.SyncImageModels {
-		if strings.Contains(model, m) {
+		if strings.Contains(model, strings.ToLower(m)) {
 			return true
 		}
 	}
 	return false
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// IsSyncImageModel
func IsSyncImageModel(model string) bool {
for _, m := range qwenSettings.SyncImageModels {
if strings.Contains(model, m) {
return true
}
}
return false
// IsSyncImageModel
func IsSyncImageModel(model string) bool {
model = strings.ToLower(model)
for _, m := range qwenSettings.SyncImageModels {
if strings.Contains(model, strings.ToLower(m)) {
return true
}
}
return false
}
🤖 Prompt for AI Agents
In `@setting/model_setting/qwen.go` around lines 42 - 49, IsSyncImageModel does a
case-sensitive substring check; change it to perform a case-insensitive
comparison by normalizing the input model to lowercase before checking against
qwenSettings.SyncImageModels (which are lowercase). In practice, update the loop
in IsSyncImageModel to compare strings.Contains(strings.ToLower(model), m) (or
otherwise lowercase the model once before the loop) so mixed-case upstream model
names match the config values.

}