Files
jonstreeter 0256779967 v1.5.0: Add trigger word extraction and auto-injection feature
- Add extract_trigger_words() method supporting Civitai, Kohya, AI Toolkit, SimpleTuner, OneTrainer
- Add auto_trigger toggle to inject trigger words at LoRA tag positions
- Add trigger_words output socket with all extracted triggers
- Enhanced lora_info output to show trigger words per LoRA
- Fix duplicate LoRA tags causing rendering issues (v1.4.1)
- Update README with new examples and documentation
- Update CHANGELOG with v1.4.1 and v1.5.0 entries
2025-12-18 07:58:08 -06:00

93 lines
2.9 KiB
Python

"""
Test script to verify LoRA tag parsing logic
"""
def parse_lora_tag(tag_content, default_weight):
"""
Simplified version of parse_lora_tag for testing
"""
parts = [p.strip() for p in tag_content.split(':')]
if len(parts) < 1 or not parts[0]:
return None
result = {
'name': parts[0],
'high_noise': default_weight,
'low_noise': default_weight,
'clip': default_weight
}
try:
if len(parts) == 2:
# Single weight: affects model only, clip uses default
weight = float(parts[1])
result['high_noise'] = weight
result['low_noise'] = weight
result['clip'] = default_weight # Use default, not the specified weight
elif len(parts) == 3:
# Dual noise: different high/low for model, clip uses default
result['high_noise'] = float(parts[1])
result['low_noise'] = float(parts[2])
result['clip'] = default_weight # Use default
elif len(parts) >= 4:
# Full control: high, low, clip all separate
result['high_noise'] = float(parts[1])
result['low_noise'] = float(parts[2])
result['clip'] = float(parts[3])
except (ValueError, IndexError) as e:
print(f"Error parsing tag '{tag_content}': {e}")
return None
return result
def test_parsing():
"""Test the parse_lora_tag function with different formats"""
default_weight = 1.0
test_cases = [
# (tag_content, expected_result, description)
("name:0.8", {"name": "name", "high_noise": 0.8, "low_noise": 0.8, "clip": 1.0},
"Single weight - should affect model only, clip uses default"),
("name:1.2:0.6", {"name": "name", "high_noise": 1.2, "low_noise": 0.6, "clip": 1.0},
"Dual weight - should affect high/low model, clip uses default"),
("name:1.2:0.6:0.9", {"name": "name", "high_noise": 1.2, "low_noise": 0.6, "clip": 0.9},
"Triple weight - full control over model and clip"),
("name", {"name": "name", "high_noise": 1.0, "low_noise": 1.0, "clip": 1.0},
"Name only - all weights use default"),
]
print("Testing LoRA tag parsing:\n")
all_passed = True
for tag_content, expected, description in test_cases:
result = parse_lora_tag(tag_content, default_weight)
if result == expected:
print(f"PASS: {description}")
print(f" Tag: <lora:{tag_content}>")
print(f" Result: {result}\n")
else:
print(f"FAIL: {description}")
print(f" Tag: <lora:{tag_content}>")
print(f" Expected: {expected}")
print(f" Got: {result}\n")
all_passed = False
if all_passed:
print("\nAll tests passed!")
else:
print("\nSome tests failed!")
return all_passed
if __name__ == "__main__":
test_parsing()