resolveModelRefs resolves a comma-separated list of model references into providers. Each reference is first looked up in the config by name; if not found it is parsed as an inline "provider/model" spec.
(ctx context.Context, commaSeparatedRefs string)
| 463 | // providers. Each reference is first looked up in the config by name; if not |
| 464 | // found it is parsed as an inline "provider/model" spec. |
| 465 | func (r *LocalRuntime) resolveModelRefs(ctx context.Context, commaSeparatedRefs string) ([]provider.Provider, error) { |
| 466 | var providers []provider.Provider |
| 467 | |
| 468 | for ref := range strings.SplitSeq(commaSeparatedRefs, ",") { |
| 469 | ref = strings.TrimSpace(ref) |
| 470 | if ref == "" { |
| 471 | continue |
| 472 | } |
| 473 | |
| 474 | // Check if this ref exists as a named model in config |
| 475 | if modelCfg, exists := r.modelSwitcherCfg.Models[ref]; exists { |
| 476 | modelCfg.Name = ref |
| 477 | prov, err := r.createProviderFromConfig(ctx, &modelCfg) |
| 478 | if err != nil { |
| 479 | return nil, fmt.Errorf("failed to create provider for %q: %w", ref, err) |
| 480 | } |
| 481 | providers = append(providers, prov) |
| 482 | continue |
| 483 | } |
| 484 | |
| 485 | // Parse as provider/model |
| 486 | inlineCfg, parseErr := latest.ParseModelRef(ref) |
| 487 | if parseErr != nil { |
| 488 | return nil, fmt.Errorf("invalid model reference %q: expected 'provider/model' format or a named model from config", ref) |
| 489 | } |
| 490 | |
| 491 | prov, err := r.createProviderFromConfig(ctx, &inlineCfg) |
| 492 | if err != nil { |
| 493 | return nil, fmt.Errorf("failed to create provider for %q: %w", ref, err) |
| 494 | } |
| 495 | providers = append(providers, prov) |
| 496 | } |
| 497 | |
| 498 | if len(providers) == 0 { |
| 499 | return nil, errors.New("no valid models found in model reference list") |
| 500 | } |
| 501 | |
| 502 | return providers, nil |
| 503 | } |
| 504 | |
| 505 | // AvailableModels implements [Runtime.AvailableModels] for LocalRuntime. |
| 506 | func (r *LocalRuntime) AvailableModels(ctx context.Context) []ModelChoice { |
no test coverage detected