mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-21 21:22:11 -03:00
feat: add model_name and version_name placeholders to download paths, #552
Add support for {model_name} and {version_name} placeholders in download path templates. These new placeholders allow for more flexible and descriptive file organization by including the actual model name and version name in the download directory structure.
Changes include:
- Updated download_manager.py and utils.py to handle new placeholders
- Added placeholders to constants.js for UI reference
- Updated settings modal template to show available placeholders
- Added comprehensive tests to verify placeholder functionality
This enhancement provides users with more control over how downloaded models are organized on their file system.
This commit is contained in:
@@ -415,8 +415,10 @@ class DownloadManager:
|
||||
base_model_mappings = settings_manager.get('base_model_path_mappings', {})
|
||||
mapped_base_model = base_model_mappings.get(base_model, base_model)
|
||||
|
||||
model_info = version_info.get('model') or {}
|
||||
|
||||
# Get model tags
|
||||
model_tags = version_info.get('model', {}).get('tags', [])
|
||||
model_tags = model_info.get('tags', [])
|
||||
|
||||
first_tag = settings_manager.resolve_priority_tag_for_model(model_tags, model_type)
|
||||
|
||||
@@ -425,6 +427,8 @@ class DownloadManager:
|
||||
formatted_path = formatted_path.replace('{base_model}', mapped_base_model)
|
||||
formatted_path = formatted_path.replace('{first_tag}', first_tag)
|
||||
formatted_path = formatted_path.replace('{author}', author)
|
||||
formatted_path = formatted_path.replace('{model_name}', model_info.get('name', ''))
|
||||
formatted_path = formatted_path.replace('{version_name}', version_info.get('name', ''))
|
||||
|
||||
if model_type == 'embedding':
|
||||
formatted_path = formatted_path.replace(' ', '_')
|
||||
|
||||
@@ -175,10 +175,18 @@ def calculate_relative_path_for_model(model_data: Dict, model_type: str = 'lora'
|
||||
first_tag = 'no tags' # Default if no tags available
|
||||
|
||||
# Format the template with available data
|
||||
model_name = model_data.get('model_name', '')
|
||||
version_name = ''
|
||||
|
||||
if isinstance(civitai_data, dict):
|
||||
version_name = civitai_data.get('name') or ''
|
||||
|
||||
formatted_path = path_template
|
||||
formatted_path = formatted_path.replace('{base_model}', mapped_base_model)
|
||||
formatted_path = formatted_path.replace('{first_tag}', first_tag)
|
||||
formatted_path = formatted_path.replace('{author}', author)
|
||||
formatted_path = formatted_path.replace('{model_name}', model_name)
|
||||
formatted_path = formatted_path.replace('{version_name}', version_name)
|
||||
|
||||
if model_type == 'embedding':
|
||||
formatted_path = formatted_path.replace(' ', '_')
|
||||
|
||||
@@ -117,7 +117,9 @@ export const DOWNLOAD_PATH_TEMPLATES = {
|
||||
export const PATH_TEMPLATE_PLACEHOLDERS = [
|
||||
'{base_model}',
|
||||
'{author}',
|
||||
'{first_tag}'
|
||||
'{first_tag}',
|
||||
'{model_name}',
|
||||
'{version_name}'
|
||||
];
|
||||
|
||||
// Default templates for each model type
|
||||
|
||||
@@ -301,6 +301,8 @@
|
||||
<span class="placeholder-tag">{base_model}</span>
|
||||
<span class="placeholder-tag">{author}</span>
|
||||
<span class="placeholder-tag">{first_tag}</span>
|
||||
<span class="placeholder-tag">{model_name}</span>
|
||||
<span class="placeholder-tag">{version_name}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -324,6 +324,22 @@ def test_embedding_relative_path_replaces_spaces():
|
||||
assert relative_path == "Base_Model/tag_with_space"
|
||||
|
||||
|
||||
def test_relative_path_supports_model_and_version_placeholders():
|
||||
manager = DownloadManager()
|
||||
settings_manager = get_settings_manager()
|
||||
settings_manager.settings["download_path_templates"]["lora"] = "{model_name}/{version_name}"
|
||||
|
||||
version_info = {
|
||||
"baseModel": "BaseModel",
|
||||
"name": "Version One",
|
||||
"model": {"name": "Fancy Model", "tags": []},
|
||||
}
|
||||
|
||||
relative_path = manager._calculate_relative_path(version_info, "lora")
|
||||
|
||||
assert relative_path == "Fancy Model/Version One"
|
||||
|
||||
|
||||
async def test_execute_download_retries_urls(monkeypatch, tmp_path):
|
||||
manager = DownloadManager()
|
||||
|
||||
|
||||
@@ -53,6 +53,21 @@ def test_calculate_relative_path_for_model_uses_mappings_and_defaults(isolated_s
|
||||
assert relative_path == "SDXL-mapped/no tags/Creator"
|
||||
|
||||
|
||||
def test_calculate_relative_path_supports_model_and_version(isolated_settings):
|
||||
isolated_settings["download_path_templates"]["lora"] = "{model_name}/{version_name}"
|
||||
|
||||
model_data = {
|
||||
"model_name": "Fancy Model",
|
||||
"base_model": "SDXL",
|
||||
"tags": ["tag"],
|
||||
"civitai": {"id": 1, "name": "Version One", "creator": {"username": "Creator"}},
|
||||
}
|
||||
|
||||
relative_path = calculate_relative_path_for_model(model_data, "lora")
|
||||
|
||||
assert relative_path == "Fancy Model/Version One"
|
||||
|
||||
|
||||
def test_calculate_recipe_fingerprint_filters_and_sorts():
|
||||
loras = [
|
||||
{"hash": "ABC", "strength": 0.1234},
|
||||
|
||||
Reference in New Issue
Block a user