MCPcopy Index your code
hub / github.com/aiprodcoder/MIXAPI / CacheGetRandomSatisfiedChannel

Function CacheGetRandomSatisfiedChannel

model/channel_cache.go:83–125  ·  view source on GitHub ↗
(c *gin.Context, group string, model string, retry int)

Source from the content-addressed store, hash-verified

81}
82
83func CacheGetRandomSatisfiedChannel(c *gin.Context, group string, model string, retry int) (*Channel, string, error) {
84 var channel *Channel
85 var err error
86 selectGroup := group
87 // 获取令牌渠道标签
88 tokenChannelTag := common.GetContextKeyString(c, constant.ContextKeyTokenChannelTag)
89 var channelTag *string = nil
90 if tokenChannelTag != "" {
91 channelTag = &tokenChannelTag
92 }
93
94 if group == "auto" {
95 if len(setting.AutoGroups) == 0 {
96 return nil, selectGroup, errors.New("auto groups is not enabled")
97 }
98 for _, autoGroup := range setting.AutoGroups {
99 if common.DebugEnabled {
100 println("autoGroup:", autoGroup)
101 }
102 channel, _ = getRandomSatisfiedChannel(autoGroup, model, retry)
103 if channel == nil {
104 continue
105 } else {
106 c.Set("auto_group", autoGroup)
107 selectGroup = autoGroup
108 if common.DebugEnabled {
109 println("selectGroup:", selectGroup)
110 }
111 break
112 }
113 }
114 } else {
115 // 传递channelTag参数给getRandomSatisfiedChannel
116 channel, err = getRandomSatisfiedChannelWithTag(group, model, retry, channelTag)
117 if err != nil {
118 return nil, group, err
119 }
120 }
121 if channel == nil {
122 return nil, group, errors.New("channel not found")
123 }
124 return channel, selectGroup, nil
125}
126
127// 新增带标签过滤的渠道选择函数
128func getRandomSatisfiedChannelWithTag(group string, model string, retry int, channelTag *string) (*Channel, error) {

Callers 2

DistributeFunction · 0.92
getChannelFunction · 0.92

Calls 3

GetContextKeyStringFunction · 0.92

Tested by

no test coverage detected