MCPcopy
hub / github.com/docker/docker-agent / AvailableModels

Method AvailableModels

pkg/runtime/model_switcher.go:506–592  ·  view source on GitHub ↗

AvailableModels implements [Runtime.AvailableModels] for LocalRuntime.

(ctx context.Context)

Source from the content-addressed store, hash-verified

504
505// AvailableModels implements [Runtime.AvailableModels] for LocalRuntime.
506func (r *LocalRuntime) AvailableModels(ctx context.Context) []ModelChoice {
507 start := time.Now()
508 if r.modelSwitcherCfg == nil {
509 slog.DebugContext(ctx, "Runtime available models skipped; model switching not configured", "duration", time.Since(start))
510 return nil
511 }
512
513 // Get the current agent's default model reference
514 currentAgentDefault := ""
515 if r.modelSwitcherCfg.AgentDefaultModels != nil {
516 currentAgentDefault = r.modelSwitcherCfg.AgentDefaultModels[r.currentAgentName()]
517 }
518
519 var choices []ModelChoice
520
521 configuredStart := time.Now()
522 // Add all configured models, marking the current agent's default
523 for name, cfg := range r.modelSwitcherCfg.Models {
524 choice := ModelChoice{
525 Name: name,
526 Ref: name,
527 Provider: cfg.Provider,
528 Model: cfg.DisplayOrModel(),
529 IsDefault: name == currentAgentDefault,
530 }
531 // Best-effort lookup of pricing / context information from models.dev.
532 if cfg.Provider != "" && cfg.Model != "" {
533 r.populateCatalogMetadata(ctx, &choice, cfg.Provider, cfg.Model)
534 }
535 choices = append(choices, choice)
536 }
537 configuredDuration := time.Since(configuredStart)
538
539 // Prefer live gateway discovery when a models gateway is configured:
540 // the picker then only shows the models actually served by the
541 // gateway, merged with the explicitly configured ones above. When the
542 // gateway doesn't expose /v1/models, fall back to the models.dev
543 // catalog filtered by available credentials.
544 if r.modelSwitcherCfg.ModelsGateway != "" {
545 gatewayStart := time.Now()
546 gatewayChoices, ok := r.buildGatewayChoices(ctx)
547 slog.DebugContext(ctx, "Runtime available models gateway discovery completed",
548 "duration", time.Since(gatewayStart),
549 "ok", ok,
550 "models", len(gatewayChoices),
551 )
552 if ok {
553 result := append(choices, gatewayChoices...)
554 slog.DebugContext(ctx, "Runtime available models completed",
555 "duration", time.Since(start),
556 "configured_duration", configuredDuration,
557 "configured_models", len(choices),
558 "gateway_models", len(gatewayChoices),
559 "catalog_models", 0,
560 "dmr_models", 0,
561 "models", len(result),
562 )
563 return result

Callers

nothing calls this directly

Calls 7

currentAgentNameMethod · 0.95
buildGatewayChoicesMethod · 0.95
buildDMRChoicesMethod · 0.95
buildCatalogChoicesMethod · 0.95
NowMethod · 0.80
DisplayOrModelMethod · 0.45

Tested by

no test coverage detected