MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / Pick

Method Pick

sdk/cliproxy/auth/selector.go:257–283  ·  view source on GitHub ↗

Pick selects the next available auth for the provider in a round-robin manner.

(ctx context.Context, provider, model string, opts cliproxyexecutor.Options, auths []*Auth)

Source from the content-addressed store, hash-verified

255
256// Pick selects the next available auth for the provider in a round-robin manner.
257func (s *RoundRobinSelector) Pick(ctx context.Context, provider, model string, opts cliproxyexecutor.Options, auths []*Auth) (*Auth, error) {
258 _ = opts
259 now := time.Now()
260 available, err := getAvailableAuths(auths, provider, model, now)
261 if err != nil {
262 return nil, err
263 }
264 available = preferCodexWebsocketAuths(ctx, provider, available)
265 key := provider + ":" + canonicalModelKey(model)
266 s.mu.Lock()
267 if s.cursors == nil {
268 s.cursors = make(map[string]int)
269 }
270 limit := s.maxKeys
271 if limit <= 0 {
272 limit = 4096
273 }
274
275 s.ensureCursorKey(key, limit)
276 index := s.cursors[key]
277 if index >= 2_147_483_640 {
278 index = 0
279 }
280 s.cursors[key] = index + 1
281 s.mu.Unlock()
282 return available[index%len(available)], nil
283}
284
285// ensureCursorKey ensures the cursor map has capacity for the given key.
286// Must be called with s.mu held.

Calls 4

ensureCursorKeyMethod · 0.95
getAvailableAuthsFunction · 0.85
canonicalModelKeyFunction · 0.85