Add prompt hygiene architecture pass

This commit is contained in:
2026-06-26 13:26:06 +02:00
parent c768b37399
commit b3cd8d77a1
7 changed files with 569 additions and 24 deletions
+27 -5
View File
@@ -10,8 +10,18 @@ from typing import Any, Callable
try:
from . import generate_prompt_batches as g
from .prompt_hygiene import (
sanitize_caption_text,
sanitize_negative_text,
sanitize_prompt_text,
)
except ImportError: # Allows local smoke tests with `python -c`.
import generate_prompt_batches as g
from prompt_hygiene import (
sanitize_caption_text,
sanitize_negative_text,
sanitize_prompt_text,
)
ROOT_DIR = Path(__file__).resolve().parent
@@ -7609,7 +7619,11 @@ def build_prompt(
row = _apply_camera_config(row, camera_config)
active_trigger = trigger.strip() or g.TRIGGER
row["prompt"] = _prepend_trigger(row["prompt"], active_trigger, bool(prepend_trigger_to_prompt))
row["negative_prompt"] = _combined_negative(row.get("negative_prompt", g.NEGATIVE_PROMPT), extra_negative)
row["prompt"] = sanitize_prompt_text(row["prompt"], triggers=(active_trigger,))
row["caption"] = sanitize_caption_text(row.get("caption", ""), triggers=(active_trigger,))
row["negative_prompt"] = sanitize_negative_text(
_combined_negative(row.get("negative_prompt", g.NEGATIVE_PROMPT), extra_negative)
)
row["trigger"] = active_trigger
row.setdefault("expression_intensity", expression_intensity)
row.setdefault("expression_intensity_source", expression_intensity_source)
@@ -8794,8 +8808,10 @@ def build_insta_of_pair(
soft_prompt = _insta_of_active_trigger(soft_prompt, active_trigger, bool(prepend_trigger_to_prompt))
hard_prompt = _insta_of_active_trigger(hard_prompt, active_trigger, bool(prepend_trigger_to_prompt))
soft_negative = _combined_negative(INSTA_OF_SOFT_NEGATIVE, extra_negative)
hard_negative = _combined_negative(INSTA_OF_NEGATIVE, extra_negative)
soft_prompt = sanitize_prompt_text(soft_prompt, triggers=(active_trigger,))
hard_prompt = sanitize_prompt_text(hard_prompt, triggers=(active_trigger,))
soft_negative = sanitize_negative_text(_combined_negative(INSTA_OF_SOFT_NEGATIVE, extra_negative))
hard_negative = sanitize_negative_text(_combined_negative(INSTA_OF_NEGATIVE, extra_negative))
soft_caption_parts = [
active_trigger,
"Insta/OF softcore mode",
@@ -8810,7 +8826,10 @@ def build_insta_of_pair(
soft_row["composition"],
_camera_caption_text(soft_camera_config) if soft_camera_directive else "",
]
soft_caption = ", ".join(str(part).strip() for part in soft_caption_parts if str(part).strip())
soft_caption = sanitize_caption_text(
", ".join(str(part).strip() for part in soft_caption_parts if str(part).strip()),
triggers=(active_trigger,),
)
hard_caption_parts = [
active_trigger,
"Insta/OF hardcore mode",
@@ -8824,7 +8843,10 @@ def build_insta_of_pair(
hard_composition,
_camera_caption_text(hard_camera_config) if hard_camera_directive else "",
]
hard_caption = ", ".join(str(part).strip() for part in hard_caption_parts if str(part).strip())
hard_caption = sanitize_caption_text(
", ".join(str(part).strip() for part in hard_caption_parts if str(part).strip()),
triggers=(active_trigger,),
)
metadata = {
"mode": "Insta/OF",
"options": options,