LoadCaps fetches (or returns from cache) the capability record for the given model ID using the provided store. When the store is nil or the model is not found, LoadCaps returns a conservative capability set that only allows text MIME types. A models.dev miss is logged once per model via [warnCapsL
(ctx context.Context, store *modelsdev.Store, id modelsdev.ID)
| 438 | // Note that the first lookup may serialize behind a shared store load: the |
| 439 | // timeout bounds the load itself, not time spent waiting for the store lock. |
| 440 | func LoadCaps(ctx context.Context, store *modelsdev.Store, id modelsdev.ID) ModelCapabilities { |
| 441 | if store == nil { |
| 442 | return ModelCapabilities{} |
| 443 | } |
| 444 | |
| 445 | ctx, cancel := context.WithTimeout(ctx, loadCapsTimeout) |
| 446 | defer cancel() |
| 447 | |
| 448 | model, err := store.GetModel(ctx, id) |
| 449 | if err != nil { |
| 450 | if ctx.Err() != nil { |
| 451 | slog.WarnContext(ctx, "modelinfo: models.dev lookup timed out, using conservative caps", |
| 452 | "model", id.String(), "timeout", loadCapsTimeout) |
| 453 | } else { |
| 454 | warnCapsLookupMiss(ctx, id, err) |
| 455 | } |
| 456 | return ModelCapabilities{} |
| 457 | } |
| 458 | |
| 459 | var mc ModelCapabilities |
| 460 | for _, input := range model.Modalities.Input { |
| 461 | switch strings.ToLower(input) { |
| 462 | case "image": |
| 463 | mc.supportsImage = true |
| 464 | case "pdf": |
| 465 | mc.supportsPDF = true |
| 466 | } |
| 467 | } |
| 468 | return mc |
| 469 | } |
| 470 | |
| 471 | // CapsWith constructs a ModelCapabilities value directly from booleans. This is |
| 472 | // intended for use in tests and provider implementations that need to create a |