PotionUI Docs v0.3.0

Reading model files and folders

A model's bytes can sit on any admin-configured root, not just the models_dir setting, so a plugin that needs a path never joins one by hand — it goes through src.plugin_api.models:

python
from src.plugin_api.models import (
    model_type_dirs, model_write_dir, resolve_model_file, model_for_path,
    model_types, directory_aliases, type_for_folder_name,
)

model_type_dirs("lora")          # -> every online root's bound directory for this type, in order
model_write_dir("lora")          # -> the directory a new download for this type lands in
resolve_model_file(model_id)     # -> the winning present copy's absolute Path, or raises
model_for_path(path)             # -> that model's catalog dict (or None), from a filesystem path
index_model_file(path, user_id=None)  # -> {model_id, indexed, duplicate_of, warning}; catalogues a file the plugin wrote

resolve_model_file raises src.features.models.locator.ModelFileUnavailable (not importable from plugin_api — catch it by class name, or by string match on reason/root_label) when the model has no present copy on any online root; the error names the root when the file is known to exist but its root is offline. model_type_dirs/model_write_dir can raise src.platform.filesystem.model_roots.ModelRootError subclasses when no root is bound for that type, is read-only, or is offline — same caveat.

index_model_file takes only an existing file inside a folder some model type writes to (a ValueError otherwise), and with user_id assigns the new model, or the catalog model it duplicates, to that user.

directory_aliases() and type_for_folder_name(name) are for a plugin that speaks another tool's folder vocabulary (a ComfyUI-style loras/checkpoints/… folder name) and needs the PotionUI model type it corresponds to, case-insensitively and including aliases.