MCPcopy Index your code
hub / github.com/docker/docker-agent / ResolveFirstAvailableModels

Function ResolveFirstAvailableModels

pkg/config/first_available.go:27–48  ·  view source on GitHub ↗

ResolveFirstAvailableModels resolves reachable `first_available` models in the config into concrete provider/model definitions by selecting the first candidate whose credentials are configured. The config is mutated in place so the rest of the pipeline (env-var gathering, model instantiation, runtim

(ctx context.Context, cfg *latest.Config, modelsGateway string, env environment.Provider)

Source from the content-addressed store, hash-verified

25// gateway is configured, the first candidate is selected since the gateway
26// supplies the credentials.
27func ResolveFirstAvailableModels(ctx context.Context, cfg *latest.Config, modelsGateway string, env environment.Provider) error {
28 // Snapshot which models are selectors before mutating the map, so the
29 // nested-selector check is independent of map iteration order.
30 selectors := map[string]bool{}
31 for name, m := range cfg.Models {
32 if m.IsFirstAvailable() {
33 selectors[name] = true
34 }
35 }
36 if len(selectors) == 0 {
37 return nil
38 }
39
40 reachable := reachableFirstAvailableModels(cfg, selectors)
41 for _, name := range sortedKeys(reachable) {
42 if err := resolveFirstAvailableModel(ctx, cfg, name, selectors, modelsGateway, env); err != nil {
43 return err
44 }
45 }
46
47 return nil
48}
49
50func resolveFirstAvailableModel(ctx context.Context, cfg *latest.Config, name string, selectors map[string]bool, modelsGateway string, env environment.Provider) error {
51 m := cfg.Models[name]

Calls 4

sortedKeysFunction · 0.85
IsFirstAvailableMethod · 0.45