Skip to content

feat: LoraManager integration — trigger words & example import (#52)#136

Merged
vitosans merged 24 commits intomainfrom
feature/52-lora-manager-integration
Apr 4, 2026
Merged

feat: LoraManager integration — trigger words & example import (#52)#136
vitosans merged 24 commits intomainfrom
feature/52-lora-manager-integration

Conversation

@vitosans
Copy link
Copy Markdown
Contributor

@vitosans vitosans commented Apr 3, 2026

Summary

Adds opt-in integration with ComfyUI-Lora-Manager as requested in #52.

  • Auto-detection: Automatically finds LoraManager in custom_nodes/ when opening Settings
  • Trigger word injection: When enabled, scans prompts for <lora:NAME:WEIGHT> tags and appends the LoRA's trigger words before CLIP encoding
  • LoRA data import: Scan LoraManager's .metadata.json files to import LoRA names, trigger words, and preview images into PromptManager's database
  • Fully opt-in: Everything is disabled by default — PromptManager remains standalone

New files

  • py/lora_utils.py — Detection, metadata parsing, trigger word cache
  • py/api/lora_integration.py — 6 API endpoints under /prompt_manager/lora/*

Modified files

  • py/config.py — New IntegrationConfig class for integration settings
  • py/api/__init__.py — Register LoraIntegrationMixin
  • prompt_manager_base.py — Trigger word injection method
  • prompt_manager.py / prompt_manager_text.py — Call injection before encoding
  • web/admin.html — Integrations section in Settings modal
  • web/js/admin.js — LoRA detection, toggle, import UI

Test plan

  • Open Settings — verify "LoraManager" appears with detection badge
  • Without LoraManager installed: badge shows "not installed", toggle disabled
  • With LoraManager installed: badge shows "detected", toggle enabled, path populated
  • Enable integration → save → reopen Settings → verify state persists in config.json
  • Click "Import LoRA Data" → verify progress notification and prompts created with lora category
  • Enable trigger words → use <lora:some_lora:1> in prompt → verify trigger words appended in output
  • Disable integration → verify trigger words are NOT injected
  • Verify PromptManager works normally when LoraManager is not installed

Closes #52

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0ae73c8b4e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

document.getElementById("resultTimeout").value = this.settings.resultTimeout;
document.getElementById("webuiDisplayMode").value = this.settings.webuiDisplayMode;
document.getElementById("galleryRootPath").value = this.settings.galleryRootPath || '';
this.renderScanPaths();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove call to undefined renderScanPaths

The settings entry point now calls this.renderScanPaths() before opening the modal, but there is no renderScanPaths method defined in web/js/admin.js. This throws a TypeError when users click Settings and prevents the rest of showSettingsModal() from running, so the settings dialog no longer opens.

Useful? React with 👍 / 👎.

meta_files = []
for d in lora_dirs:
dir_path = Path(d)
meta_files.extend(dir_path.glob("*.metadata.json"))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Recursively scan metadata files during LoRA import

The import path only uses glob("*.metadata.json") per discovered directory, so metadata files in nested LoRA subfolders are skipped. In setups where models/loras is organized into subdirectories, the scan will under-import LoRAs and their previews while reporting completion, which makes imported results incomplete.

Useful? React with 👍 / 👎.

py/lora_utils.py Outdated
lora_dirs = find_lora_directories(lora_manager_path)
for lora_dir in lora_dirs:
dir_path = Path(lora_dir)
for meta_file in dir_path.glob("*.metadata.json"):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Recursively build trigger cache from metadata files

TriggerWordCache.load() also uses non-recursive glob("*.metadata.json"), so LoRAs whose metadata is stored in nested folders are never cached. When users reference those LoRAs with <lora:...> tags, trigger-word injection silently does nothing even though integration is enabled.

Useful? React with 👍 / 👎.

vitosans added 5 commits April 3, 2026 07:28
Detection, metadata reading, trigger word cache, and prompt injection
for ComfyUI-Lora-Manager. All functions return empty results when
LoraManager is not installed.
Detection, enable/disable, scan/import, trigger word lookup,
and cache refresh endpoints under /prompt_manager/lora/*.
When enabled, scans for <lora:NAME:WEIGHT> tags in prompt text and
appends trigger words from LoraManager metadata. Behind config toggle.
Integrations section in settings with auto-detection badge, enable
toggle, trigger word toggle, and Import LoRA Data button.
@vitosans vitosans force-pushed the feature/52-lora-manager-integration branch from 0ae73c8 to 062f430 Compare April 3, 2026 14:28
vitosans added 4 commits April 3, 2026 08:01
The styled div was intercepting clicks meant for the sr-only checkbox
input, preventing toggle switches from being clickable.
…#52)

Only models/loras under the ComfyUI root was checked. Now also parses
extra_model_paths.yaml and uses folder_paths.get_folder_paths('loras')
at runtime to find all configured LoRA directories.
… images (#52)

- Prompt text now uses civitai example prompts (images[].meta.prompt)
  when available, falling back to model name instead of trigger words
- Image serving now allows paths within LoRA directories when the
  integration is enabled, fixing 403 errors on preview images
vitosans added 3 commits April 3, 2026 08:24
- Guard against civitai: null in metadata (was crashing the scan)
- Link all local preview images per LoRA, not just the first
- Add get_civitai_image_urls() for future remote image support
Clicking Import LoRA Data now deletes all existing lora-manager
category prompts before scanning, ensuring a clean reimport.
Images from civitai.images[] are downloaded to data/lora_images/ cache
and linked to prompts alongside local preview files. Cached files are
reused on reimport. Image serving allows the cache directory.
vitosans added 7 commits April 3, 2026 08:41
)

Most civitai example images (especially NSFW) require authentication.
Adds API key field to the Integrations settings panel, passed as
Bearer token when downloading example images.
Closes settings modal and shows a dedicated progress modal with
progress bar, status text, and processed/imported counts during
LoRA import. Auto-closes after completion.
5K images at 15s timeout was painfully slow. Reduced to 5s fail-fast.
Progress now updates for every LoRA with image count, not every 5th.
Full-size civitai images averaged 5.6MB each (27GB total for 5K images).
Now requests /width=512/ thumbnails (~50-100KB) and downloads 8 in
parallel per LoRA. Expected speedup: ~100x smaller + 8x parallel.
Civitai CDN returns 401 for /width=N/ thumbnail URLs with API key auth.
Instead, download the original and resize to 512px via PIL before saving.
Reduces disk usage from ~5MB to ~30-50KB per image.
- Add LoRA Manager integration section with setup guide and CivitAI key docs
- Add folder filter section with rescan note for existing libraries
- Add v3.2.1 changelog entry, split from v3.2.0
- Add WIP notice for LoRA Manager feature
- Update AutoTag section to include WD14 models
- Fix stale references (KikoTextEncode, outdated file structure)
- Remove dated v2 development note
- Add screenshots for settings, integration, and filtered results
- Fix code review items: remove unused constant, add comments to empty excepts
- Bump version to 3.2.1
- test_lora_utils.py: 32 tests covering trigger word extraction, example
  prompts, image URLs, metadata parsing, cache dir, TriggerWordCache
- test_lora_database.py: 17 tests covering delete_prompts_by_category,
  folder filter search, get_prompt_subfolders, LoRA import workflow
- test_config.py: 7 new IntegrationConfig tests for structure, enable,
  partial update, reset, and roundtrip
@vitosans vitosans merged commit 00284d9 into main Apr 4, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Request Feature Integrate with loraManager's example folder

1 participant