fix: 模型列表仅显示已启用渠道中的模型
This commit is contained in:
@@ -87,6 +87,20 @@ func (s *Service) loadBound(bindings []store.ChannelModelBinding) []Candidate {
|
||||
return out
|
||||
}
|
||||
|
||||
// AvailableModelIDs 返回对外可见的模型 ID:启用的模型且至少绑定到一个启用且健康的渠道。
|
||||
// 与 Candidates 的过滤口径一致(enabled + health_status=healthy),避免暴露绑定到已停用渠道的模型。
|
||||
func (s *Service) AvailableModelIDs() []uint64 {
|
||||
var ids []uint64
|
||||
s.db.Model(&store.ChannelModelBinding{}).
|
||||
Joins("JOIN channels ON channels.id = channel_model_bindings.channel_id").
|
||||
Joins("JOIN models ON models.id = channel_model_bindings.model_id").
|
||||
Where("channels.enabled = ? AND channels.health_status = ?", true, store.ChannelHealthHealthy).
|
||||
Where("models.enabled = ?", true).
|
||||
Distinct("channel_model_bindings.model_id").
|
||||
Pluck("channel_model_bindings.model_id", &ids)
|
||||
return ids
|
||||
}
|
||||
|
||||
// Pick 按权重加权随机选一个候选渠道(负载均衡)。
|
||||
func (s *Service) Pick(cands []Candidate) *store.Channel {
|
||||
if len(cands) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user