fix(channel): load model mapping during upstream model checks
This commit is contained in:
@@ -32,6 +32,26 @@ const (
|
|||||||
channelUpstreamModelUpdateNotifyMaxFailedChannelIDs = 10
|
channelUpstreamModelUpdateNotifyMaxFailedChannelIDs = 10
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var channelUpstreamModelUpdateSelectFields = []string{
|
||||||
|
"id",
|
||||||
|
"name",
|
||||||
|
"type",
|
||||||
|
"key",
|
||||||
|
"status",
|
||||||
|
"base_url",
|
||||||
|
"models",
|
||||||
|
"model_mapping",
|
||||||
|
"settings",
|
||||||
|
"setting",
|
||||||
|
"other",
|
||||||
|
"group",
|
||||||
|
"priority",
|
||||||
|
"weight",
|
||||||
|
"tag",
|
||||||
|
"channel_info",
|
||||||
|
"header_override",
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
channelUpstreamModelUpdateTaskOnce sync.Once
|
channelUpstreamModelUpdateTaskOnce sync.Once
|
||||||
channelUpstreamModelUpdateTaskRunning atomic.Bool
|
channelUpstreamModelUpdateTaskRunning atomic.Bool
|
||||||
@@ -521,7 +541,7 @@ func runChannelUpstreamModelUpdateTaskOnce() {
|
|||||||
for {
|
for {
|
||||||
var channels []*model.Channel
|
var channels []*model.Channel
|
||||||
query := model.DB.
|
query := model.DB.
|
||||||
Select("id", "name", "type", "key", "status", "base_url", "models", "settings", "setting", "other", "group", "priority", "weight", "tag", "channel_info", "header_override").
|
Select(channelUpstreamModelUpdateSelectFields).
|
||||||
Where("status = ?", common.ChannelStatusEnabled).
|
Where("status = ?", common.ChannelStatusEnabled).
|
||||||
Order("id asc").
|
Order("id asc").
|
||||||
Limit(channelUpstreamModelUpdateTaskBatchSize)
|
Limit(channelUpstreamModelUpdateTaskBatchSize)
|
||||||
@@ -814,7 +834,7 @@ func collectPendingApplyUpstreamModelChanges(settings dto.ChannelOtherSettings)
|
|||||||
func findEnabledChannelsAfterID(lastID int, batchSize int) ([]*model.Channel, error) {
|
func findEnabledChannelsAfterID(lastID int, batchSize int) ([]*model.Channel, error) {
|
||||||
var channels []*model.Channel
|
var channels []*model.Channel
|
||||||
query := model.DB.
|
query := model.DB.
|
||||||
Select("id", "name", "type", "key", "status", "base_url", "models", "settings", "setting", "other", "group", "priority", "weight", "tag", "channel_info", "header_override").
|
Select(channelUpstreamModelUpdateSelectFields).
|
||||||
Where("status = ?", common.ChannelStatusEnabled).
|
Where("status = ?", common.ChannelStatusEnabled).
|
||||||
Order("id asc").
|
Order("id asc").
|
||||||
Limit(batchSize)
|
Limit(batchSize)
|
||||||
|
|||||||
@@ -81,6 +81,10 @@ func TestCollectPendingApplyUpstreamModelChanges(t *testing.T) {
|
|||||||
require.Equal(t, []string{"old-model"}, pendingRemoveModels)
|
require.Equal(t, []string{"old-model"}, pendingRemoveModels)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestChannelUpstreamModelUpdateSelectFieldsIncludeModelMapping(t *testing.T) {
|
||||||
|
require.Contains(t, channelUpstreamModelUpdateSelectFields, "model_mapping")
|
||||||
|
}
|
||||||
|
|
||||||
func TestNormalizeChannelModelMapping(t *testing.T) {
|
func TestNormalizeChannelModelMapping(t *testing.T) {
|
||||||
modelMapping := `{
|
modelMapping := `{
|
||||||
" alias-model ": " upstream-model ",
|
" alias-model ": " upstream-model ",
|
||||||
|
|||||||
Reference in New Issue
Block a user