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

Method runModelRegistrationTaskPhase

sdk/cliproxy/service.go:275–335  ·  view source on GitHub ↗
(ctx context.Context, tasks []modelRegistrationTask, compatCache *openAICompatibilityRegistrationCache)

Source from the content-addressed store, hash-verified

273}
274
275func (s *Service) runModelRegistrationTaskPhase(ctx context.Context, tasks []modelRegistrationTask, compatCache *openAICompatibilityRegistrationCache) {
276 if len(tasks) == 0 {
277 return
278 }
279
280 grouped := make(map[string][]modelRegistrationTask)
281 order := make([]string, 0)
282 for _, task := range tasks {
283 if task.run == nil {
284 continue
285 }
286 category := strings.ToLower(strings.TrimSpace(task.category))
287 if category == "" {
288 category = "unknown"
289 }
290 if _, exists := grouped[category]; !exists {
291 order = append(order, category)
292 }
293 grouped[category] = append(grouped[category], task)
294 }
295
296 var wg sync.WaitGroup
297 for _, category := range order {
298 group := grouped[category]
299 workers := len(group)
300 maxWorkers := modelRegistrationMaxWorkersForCategory(category)
301 if workers > maxWorkers {
302 workers = maxWorkers
303 }
304 if workers <= 0 {
305 continue
306 }
307
308 taskCh := make(chan modelRegistrationTask)
309 for i := 0; i < workers; i++ {
310 wg.Add(1)
311 go func() {
312 defer wg.Done()
313 for task := range taskCh {
314 select {
315 case <-ctx.Done():
316 return
317 default:
318 }
319 task.run(compatCache)
320 }
321 }()
322 }
323 go func(group []modelRegistrationTask) {
324 defer close(taskCh)
325 for _, task := range group {
326 select {
327 case <-ctx.Done():
328 return
329 case taskCh <- task:
330 }
331 }
332 }(group)

Callers 1

Calls 2

runMethod · 0.45

Tested by

no test coverage detected