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

Method resolveModelRef

pkg/runtime/model_switcher.go:412–433  ·  view source on GitHub ↗

resolveModelRef resolves a model reference to a single provider. The reference can be a named model from the config or an inline "provider/model" spec (e.g. "openai/gpt-4o-mini").

(ctx context.Context, modelRef string)

Source from the content-addressed store, hash-verified

410// The reference can be a named model from the config or an inline
411// "provider/model" spec (e.g. "openai/gpt-4o-mini").
412func (r *LocalRuntime) resolveModelRef(ctx context.Context, modelRef string) (provider.Provider, error) {
413 if r.modelSwitcherCfg == nil {
414 return nil, errors.New("model switching not configured for this runtime")
415 }
416
417 // Try named model from config first.
418 if modelCfg, exists := r.modelSwitcherCfg.Models[modelRef]; exists {
419 if isAlloyModelConfig(modelCfg) {
420 return nil, fmt.Errorf("model reference %q is an alloy (multi-model) config and cannot be used as a single model override", modelRef)
421 }
422 modelCfg.Name = modelRef
423 return r.createProviderFromConfig(ctx, &modelCfg)
424 }
425
426 // Try inline "provider/model" format.
427 inlineCfg, err := latest.ParseModelRef(modelRef)
428 if err != nil {
429 return nil, fmt.Errorf("invalid model reference %q: expected a model name from config or 'provider/model' format", modelRef)
430 }
431
432 return r.createProviderFromConfig(ctx, &inlineCfg)
433}
434
435// isAlloyModelConfig checks if a model config is an alloy model (multiple models).
436func isAlloyModelConfig(cfg latest.ModelConfig) bool {

Calls 4

ParseModelRefFunction · 0.92
isAlloyModelConfigFunction · 0.70
NewMethod · 0.45