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)
| 410 | // The reference can be a named model from the config or an inline |
| 411 | // "provider/model" spec (e.g. "openai/gpt-4o-mini"). |
| 412 | func (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). |
| 436 | func isAlloyModelConfig(cfg latest.ModelConfig) bool { |