mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-21 21:22:11 -03:00
fix(trigger_word_toggle): add trigger word normalization method
Introduce a new private method `_normalize_trigger_words` to handle consistent splitting and cleaning of trigger word strings. This method splits input by both single and double commas, strips whitespace, and filters out empty strings, returning a set of normalized words. It is now used in `process_trigger_words` to compare trigger word overrides, ensuring accurate detection of changes by comparing normalized sets instead of raw strings.
This commit is contained in:
@@ -60,6 +60,22 @@ class TriggerWordToggleLM:
|
|||||||
else:
|
else:
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def _normalize_trigger_words(self, trigger_words):
|
||||||
|
"""Normalize trigger words by splitting by both single and double commas, stripping whitespace, and filtering empty strings"""
|
||||||
|
if not trigger_words or not isinstance(trigger_words, str):
|
||||||
|
return set()
|
||||||
|
|
||||||
|
# Split by double commas first to preserve groups, then by single commas
|
||||||
|
groups = re.split(r",{2,}", trigger_words)
|
||||||
|
words = []
|
||||||
|
for group in groups:
|
||||||
|
# Split each group by single comma
|
||||||
|
group_words = [word.strip() for word in group.split(",")]
|
||||||
|
words.extend(group_words)
|
||||||
|
|
||||||
|
# Filter out empty strings and return as set
|
||||||
|
return set(word for word in words if word)
|
||||||
|
|
||||||
def process_trigger_words(
|
def process_trigger_words(
|
||||||
self,
|
self,
|
||||||
id,
|
id,
|
||||||
@@ -81,7 +97,7 @@ class TriggerWordToggleLM:
|
|||||||
if (
|
if (
|
||||||
trigger_words_override
|
trigger_words_override
|
||||||
and isinstance(trigger_words_override, str)
|
and isinstance(trigger_words_override, str)
|
||||||
and trigger_words_override != trigger_words
|
and self._normalize_trigger_words(trigger_words_override) != self._normalize_trigger_words(trigger_words)
|
||||||
):
|
):
|
||||||
filtered_triggers = trigger_words_override
|
filtered_triggers = trigger_words_override
|
||||||
return (filtered_triggers,)
|
return (filtered_triggers,)
|
||||||
|
|||||||
Reference in New Issue
Block a user