Skip to content
Open
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
7 changes: 7 additions & 0 deletions controller/channel-test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
56 changes: 56 additions & 0 deletions controller/channel_test_endpoint_test.go
Original file line number Diff line number Diff line change
@@ -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),
),
)
}