feat: support upstream model fetch for advanced custom channels (#5971)

* feat: support upstream model fetch for advanced custom channels

* fix: add advanced custom routes as separate groups

* fix: select advanced custom route entry before adding

---------

Co-authored-by: CaIon <i@caion.me>
This commit is contained in:
Seefs
2026-07-18 13:39:53 +08:00
committed by GitHub
co-authored by CaIon
parent 57746fc972
commit a6cf42c0f1
24 changed files with 1324 additions and 135 deletions
+5
View File
@@ -962,6 +962,11 @@ func (channel *Channel) ValidateSettings() error {
return err
}
}
if channel.Type == constant.ChannelTypeAdvancedCustom && channelOtherSettings.UpstreamModelUpdateCheckEnabled {
if _, ok := channelOtherSettings.AdvancedCustom.ModelListRoute(); !ok {
return fmt.Errorf("advanced custom channels require a %s route when upstream model update checks are enabled", dto.AdvancedCustomModelListPath)
}
}
return nil
}
+68
View File
@@ -0,0 +1,68 @@
package model
import (
"testing"
"github.com/QuantumNous/new-api/constant"
"github.com/QuantumNous/new-api/dto"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAdvancedCustomChannelRequiresModelListRouteOnlyWhenUpdateChecksEnabled(t *testing.T) {
inferenceRoute := dto.AdvancedCustomRoute{
IncomingPath: "/v1/chat/completions",
UpstreamPath: "/v1/chat/completions",
Converter: "none",
}
tests := []struct {
name string
checksEnabled bool
routes []dto.AdvancedCustomRoute
wantErr string
}{
{
name: "legacy channel without discovery route remains valid",
routes: []dto.AdvancedCustomRoute{inferenceRoute},
},
{
name: "enabled checks require discovery route",
checksEnabled: true,
routes: []dto.AdvancedCustomRoute{inferenceRoute},
wantErr: dto.AdvancedCustomModelListPath,
},
{
name: "enabled checks accept discovery route",
checksEnabled: true,
routes: []dto.AdvancedCustomRoute{
inferenceRoute,
{
IncomingPath: dto.AdvancedCustomModelListPath,
UpstreamPath: dto.AdvancedCustomModelListPath,
Converter: "none",
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
channel := &Channel{Type: constant.ChannelTypeAdvancedCustom}
channel.SetOtherSettings(dto.ChannelOtherSettings{
UpstreamModelUpdateCheckEnabled: tt.checksEnabled,
AdvancedCustom: &dto.AdvancedCustomConfig{
Routes: tt.routes,
},
})
err := channel.ValidateSettings()
if tt.wantErr == "" {
require.NoError(t, err)
return
}
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
})
}
}