PotionUI Docs v0.3.0

Reading presets

src.plugin_api.presets describes the presets of this instance, so a plugin can offer a user a choice of presets and fill a request for the one they pick.

FunctionDoes
list_presets(user)A PresetDescription for each installed preset user may run, in the order GET /api/presets lists presets: the presets assigned to them directly or through one of their groups, the rule submit_generation checks, and every installed preset for an administrator. An installed preset whose files are not loaded is left out. Without a user it raises PermissionError
describe_preset(preset_id)The PresetDescription of a loaded preset, installed or not, or None when no preset with that id is loaded: its id and name, a copy of its vars, its modes (each with its default_form and every form's fields as type, required and multi), its engine and category, and requires, a copy of the requires: block of its preset.yml (such as {"min_vram_gb": 12, "recommended_vram_gb": 16}) or None
preset_template(preset_id)The PresetTemplate of a loaded preset as its loader built it, installed or not, or None: its path on this server, its driver, and its modes down to each form field and its configuration, recommended model files included. It is a deep copy: changing it changes nothing in the loaded preset. Its fields are those the loader builds (src/features/presets/templates.py) and follow it; they are not a stable contract until the plugin API's stability question (issue #36) is answered, so read the fields you need and expect them to move
resolve_preset_path(preset_id, reference)reference, a path a preset names (such as the path of a field's option file), with its {{ paths.preset }} and {{ paths._shared }} variables replaced by the preset's folder and the shared presets folder, then resolved, links followed. None when the preset is not loaded, or when the resolved path is not inside the preset's folder or the shared presets folder: a .. that climbs out, an absolute path elsewhere, a drive letter, a UNC path, or a symbolic link or junction that leads out. On Windows the check ignores case, as the file system does. A path without either variable is resolved against the server's working directory, as the loader reads it, so it is None unless it lands in one of the two folders
preset_install_state(preset_id)A PresetInstallState: installed, whether an administrator installed the preset, and assigned, whether it is then assigned to at least one user or group. A preset that is not installed is never assigned

Only list_presets(user) is scoped to a user: it lists what they may run and says nothing of the other presets. describe_preset, preset_template, resolve_preset_path and preset_install_state are not scoped to a user. They take no user and read the presets of the instance, whoever asks: the first three read any loaded preset, installed, assigned or not, and preset_install_state tells about any preset id. Before you show a user what one of them reads, check that list_presets(user) lists that preset. preset_install_state is for what administrators see, such as a setup check, and a PresetTemplate holds paths on this server.