Skip to content
Merged
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
27 changes: 15 additions & 12 deletions controller/channel-test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ func testChannel(channel *model.Channel, testModel string, endpointType string)
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)

testModel = strings.TrimSpace(testModel)
if testModel == "" {
if channel.TestModel != nil && *channel.TestModel != "" {
testModel = strings.TrimSpace(*channel.TestModel)
} else {
models := channel.GetModels()
if len(models) > 0 {
testModel = strings.TrimSpace(models[0])
}
if testModel == "" {
testModel = "gpt-4o-mini"
}
}
}
Comment on lines +62 to +75

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 | 🟠 Major

Handle whitespace-only channel.TestModel values.

If channel.TestModel contains only whitespace (e.g., " "), line 64's check passes (*channel.TestModel != ""), line 65 trims it to an empty string, but the fallback logic in lines 67-72 is skipped. This leaves testModel empty, which could cause request failures downstream.

Apply this diff to ensure fallbacks are checked after trimming:

 testModel = strings.TrimSpace(testModel)
 if testModel == "" {
-	if channel.TestModel != nil && *channel.TestModel != "" {
+	if channel.TestModel != nil {
 		testModel = strings.TrimSpace(*channel.TestModel)
+	}
+	if testModel == "" {
+		models := channel.GetModels()
+		if len(models) > 0 {
+			testModel = strings.TrimSpace(models[0])
+		}
+	}
+	if testModel == "" {
+		testModel = "gpt-4o-mini"
-	} else {
-		models := channel.GetModels()
-		if len(models) > 0 {
-			testModel = strings.TrimSpace(models[0])
-		}
-		if testModel == "" {
-			testModel = "gpt-4o-mini"
-		}
 	}
 }

This flattens the conditional structure so each fallback is evaluated in sequence, ensuring empty results trigger the next fallback.

📝 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
testModel = strings.TrimSpace(testModel)
if testModel == "" {
if channel.TestModel != nil && *channel.TestModel != "" {
testModel = strings.TrimSpace(*channel.TestModel)
} else {
models := channel.GetModels()
if len(models) > 0 {
testModel = strings.TrimSpace(models[0])
}
if testModel == "" {
testModel = "gpt-4o-mini"
}
}
}
testModel = strings.TrimSpace(testModel)
if testModel == "" {
if channel.TestModel != nil {
testModel = strings.TrimSpace(*channel.TestModel)
}
if testModel == "" {
models := channel.GetModels()
if len(models) > 0 {
testModel = strings.TrimSpace(models[0])
}
}
if testModel == "" {
testModel = "gpt-4o-mini"
}
}
}
🤖 Prompt for AI Agents
In controller/channel-test.go around lines 62 to 75, the current nested
conditional treats a whitespace-only channel.TestModel as non-empty and skips
fallbacks; change the logic to first trim testModel and, if empty, check
channel.TestModel (trimmed) and if still empty evaluate channel.GetModels() (use
first trimmed model if present), and finally set the default "gpt-4o-mini" if
all previous results are empty; flatten the conditionals so each fallback is
evaluated in sequence after trimming.


requestPath := "/v1/chat/completions"

// 如果指定了端点类型,使用指定的端点类型
Expand Down Expand Up @@ -90,18 +105,6 @@ func testChannel(channel *model.Channel, testModel string, endpointType string)
Header: make(http.Header),
}

if testModel == "" {
if channel.TestModel != nil && *channel.TestModel != "" {
testModel = *channel.TestModel
} else {
if len(channel.GetModels()) > 0 {
testModel = channel.GetModels()[0]
} else {
testModel = "gpt-4o-mini"
}
}
}

cache, err := model.GetUserCache(1)
if err != nil {
return testResult{
Expand Down