diff --git a/controller/channel-test.go b/controller/channel-test.go index 4ba3698bd54c..21484e5d38d9 100644 --- a/controller/channel-test.go +++ b/controller/channel-test.go @@ -52,6 +52,13 @@ func normalizeChannelTestEndpoint(channel *model.Channel, modelName, endpointTyp if channel != nil && channel.Type == constant.ChannelTypeCodex { return string(constant.EndpointTypeOpenAIResponse) } + if channel != nil && service.ShouldChatCompletionsUseResponsesGlobal( + channel.Id, + channel.Type, + modelName, + ) { + return string(constant.EndpointTypeOpenAIResponse) + } return normalized } diff --git a/controller/channel_test_endpoint_test.go b/controller/channel_test_endpoint_test.go new file mode 100644 index 000000000000..f93bb0a31d70 --- /dev/null +++ b/controller/channel_test_endpoint_test.go @@ -0,0 +1,56 @@ +package controller + +import ( + "testing" + + "github.com/QuantumNous/new-api/constant" + "github.com/QuantumNous/new-api/model" + "github.com/QuantumNous/new-api/setting/model_setting" + + "github.com/stretchr/testify/assert" +) + +func TestNormalizeChannelTestEndpointUsesResponsesCompatibilityPolicy(t *testing.T) { + settings := model_setting.GetGlobalSettings() + previous := settings.ChatCompletionsToResponsesPolicy + settings.ChatCompletionsToResponsesPolicy = model_setting.ChatCompletionsToResponsesPolicy{ + Enabled: true, + ChannelIDs: []int{4}, + ModelPatterns: []string{"^gpt-5.*$"}, + } + t.Cleanup(func() { + settings.ChatCompletionsToResponsesPolicy = previous + }) + + channel := &model.Channel{Id: 4, Type: constant.ChannelTypeOpenAI} + assert.Equal( + t, + string(constant.EndpointTypeOpenAIResponse), + normalizeChannelTestEndpoint(channel, "gpt-5.6-sol", ""), + ) + assert.Empty( + t, + normalizeChannelTestEndpoint(channel, "claude-3-7-sonnet", ""), + ) + assert.Empty( + t, + normalizeChannelTestEndpoint( + &model.Channel{Id: 5, Type: constant.ChannelTypeOpenAI}, + "gpt-5.6-sol", + "", + ), + ) +} + +func TestNormalizeChannelTestEndpointKeepsExplicitEndpoint(t *testing.T) { + channel := &model.Channel{Id: 4, Type: constant.ChannelTypeOpenAI} + assert.Equal( + t, + string(constant.EndpointTypeOpenAI), + normalizeChannelTestEndpoint( + channel, + "gpt-5.6-sol", + string(constant.EndpointTypeOpenAI), + ), + ) +}