feat(assets) Add asset file_path and display_name response fields#14005
feat(assets) Add asset file_path and display_name response fields#14005synap5e wants to merge 3 commits into
Conversation
Amp-Thread-ID: https://ampcode.com/threads/T-019e4307-dd77-7709-b9f4-46bb79dcf58a Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019e4307-dd77-7709-b9f4-46bb79dcf58a Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019e4307-dd77-7709-b9f4-46bb79dcf58a Co-authored-by: Amp <amp@ampcode.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughThis PR extends the Asset API model to expose logical file paths and display names. It introduces path computation helpers in 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
|
Heads up on the Two cleaner options:
(1) is the smaller change and avoids introducing dual conventions in the same file. |
| `bucket` is only set for model assets. The returned relative path always | ||
| uses `/` separators and is empty when the path is exactly the matched root. |
There was a problem hiding this comment.
I think this function relies on a flawed assumption that all models will be in the models directory. As an example, the built-in SaveCheckpoint, SaveLora, etc. models actually save to the outputs directory but are still loadable as models.
If possible, I would really like to avoid special-casing models as that's usually going to fail for edge cases. Could you explain a bit more about why we actually need the bucket as a first-class concept?
| def get_asset_category_and_relative_path( | ||
| file_path: str, | ||
| ) -> tuple[Literal["input", "output", "temp", "models"], str]: | ||
| ) -> tuple[RootCategory, str]: |
There was a problem hiding this comment.
I know this isn't actually new to this PR, but I'm a little concerned about the assumption that models will be exactly one of these. We should make sure this works for cases like the built-in SaveCheckpoint or SaveLora nodes where the model is located under the outputs directory, but should also be treated as a model.
What this does
Adds 2 new optional fields to the asset system's
Asset(andAssetCreated) schema:file_path: The asset's path on disk (if it has one). Includes themodels/{checkpoints,vae,...}/or{input,output}/prefix.display_name: The asset's human-readable display name. Conventionally a the path within prefix, and what is displayed in the loading widget.Motivation
In asset mode, the asset response's
namefield is overloaded. Depending on the asset's origin, the same field carries:In asset-mode, the frontend has ~10 widget and upload sites that read
nameor fall back toasset_hashto extract whichever role they need, with per-backend branching where the heuristics differ.file_pathexposes the full namespace-relative locator (models/checkpoints/flux/model.safetensors) as a dedicated field.display_nameexposes the within-bucket path (flux/model.safetensors). The frontend can read what it needs without inferring from value shape or branching on backend.Changes
file_pathanddisplay_nameto theAssetoutput schema, inherited byAssetCreated.{input,output,temp}/...models/<bucket>/...exclude_noneresponse behavior.Verification
uv run --with-requirements requirements.txt --with-requirements tests-unit/requirements.txt pytest -q tests-unit/assets_test/services/test_path_utils.py tests-unit/assets_test/test_uploads.py::test_upload_response_includes_file_path_and_display_name tests-unit/assets_test/test_uploads.py::test_upload_fastpath_from_existing_hash_no_file tests-unit/assets_test/test_crud.py::test_metadata_filename_is_set_for_seed_asset_without_hashuv run --with ruff ruff check app/assets/api/routes.py app/assets/api/schemas_out.py app/assets/services/path_utils.py tests-unit/assets_test/services/test_path_utils.py tests-unit/assets_test/test_uploads.py tests-unit/assets_test/test_crud.py