Add comma support to vocabulary patterns

- Use [!,] character class to catch both 'Fantastic!' and 'Fantastic,'
- SpongeBob phrases always end with ! - emphasis carries the emotion
- Added Brilliant patterns (both cases)
- Cleaner pattern structure with captured whitespace group
This commit is contained in:
BarnacleBoy 2026-05-09 20:58:04 +00:00
parent d97e28467d
commit 150178bc12

View file

@ -35,59 +35,59 @@ OPENING_INTERJECTIONS = [
# Vocabulary replacements - case-insensitive regex patterns # Vocabulary replacements - case-insensitive regex patterns
# Format: (pattern, replacement) # Format: (pattern, replacement)
# Uses [!,] to match both exclamation and comma contexts
# SpongeBob phrases always end with ! - the emphasis carries the emotion
VOCABULARY_PATTERNS = [ VOCABULARY_PATTERNS = [
# Exclamations (surprise, excitement) - standalone or at start # Wow - surprise/excitement
(r'\bWow!\s', 'Tartar sauce! '), (r'\bWow[!,](\s)', r'Tartar sauce!\1'), # Wow! or Wow, → Tartar sauce!
(r'\bWow!\Z', 'Tartar sauce!'), (r'\bWow!\Z', 'Tartar sauce!'), # Wow! at end of string
(r'\bWow,', 'Tartar sauce,'), (r'\bWow,', 'Tartar sauce,'), # Keep existing comma pattern for variety
# Amazing variations # Amazing - praise/excitement
(r'\b[Aa]mazing!\s', 'Holy Krabby Patties! '), (r'\b[Aa]mazing[!,](\s)', r'Holy Krabby Patties!\1'),
(r'\b[Aa]mazing!\Z', 'Holy Krabby Patties!'), (r'\b[Aa]mazing!\Z', 'Holy Krabby Patties!'),
# Excellent # Excellent -satisfaction
(r'\b[Ee]xcellent!\s', 'Holy fish paste! '), (r'\b[Ee]xcellent[!,](\s)', r'Holy fish paste!\1'),
(r'\b[Ee]xcellent!\Z', 'Holy fish paste!'), (r'\b[Ee]xcellent!\Z', 'Holy fish paste!'),
# Great # Great -emphasis (case-sensitive, only "Great" not "great")
(r'\bGreat!\s', 'Barnacles! '), (r'\bGreat[!,](\s)', r'Barnacles!\1'),
(r'\bGreat!\Z', 'Barnacles!'), (r'\bGreat!\Z', 'Barnacles!'),
# Perfect # Perfect - satisfaction
(r'\b[Pp]erfect!\s', 'Holy cephalopod! '), (r'\b[Pp]erfect[!,](\s)', r'Holy cephalopod!\1'),
(r'\b[Pp]erfect!\Z', 'Holy cephalopod!'), (r'\b[Pp]erfect!\Z', 'Holy cephalopod!'),
# Fantastic # Fantastic - excitement/praise
(r'\b[Ff]antastic!\s', 'Holy shrimp! '), (r'\b[Ff]antastic[!,](\s)', r'Holy shrimp!\1'),
(r'\b[Ff]antastic!\Z', 'Holy shrimp!'), (r'\b[Ff]antastic!\Z', 'Holy shrimp!'),
# Brilliant # Brilliant - praise (British flavor, matches both cases)
(r'\bBrilliant!', 'Great Barrier Reef!'), (r'\b[Bb]rilliant[!,](\s)', r'Great Barrier Reef!\1'),
(r'\b[Bb]rilliant!\Z', 'Great Barrier Reef!'),
# Damn frustration # Damn - frustration/mild swearing
(r'\b[Dd]amn!', 'Barnacles!'), (r'\b[Dd]amn!', 'Barnacles!'), # Damn! → Barnacles!
(r'\b[Dd]amn,', 'Aw, barnacles,'), (r'\b[Dd]amn,', 'Aw, barnacles,'), # Damn, → Aw, barnacles,
# Ugh frustration # Ugh - frustration
(r'\bUgh!', 'Fish paste!'), (r'\bUgh!', 'Fish paste!'), # Ugh! → Fish paste!
(r'\bUgh,', 'Aw, fish paste!'), (r'\bUgh,', 'Aw, fish paste!'), # Ugh, → Aw, fish paste!
# Fantastic praise # Common openers - conversational fillers
(r'\b[Ff]antastic!', 'Mother of Pearl!'), (r'\bWell,', "Flappin' flounders,"), # Well, → Flappin' flounders,
(r'\bOh,', 'Oh, barnacles,'), # Oh, → Oh, barnacles,
# Common openers
(r'\bWell,', "Flappin' flounders,"),
(r'\bOh,', 'Oh, barnacles,'),
] ]
# Patterns to preserve (never transform) # Patterns to preserve (never transform)
PRESERVE_PATTERNS = [ PRESERVE_PATTERNS = [
r'```[\s\S]*?```', # Code blocks r'```[\s\S]*?```', # Code blocks
r'`[^`]+`', # Inline code r'`[^`]+`', # Inline code
r'https?://[^\s]+', # URLs r'https?://[^\s]+', # URLs
r'~/[^\s]+', # File paths starting with ~ r'~/[^\s]+', # File paths starting with ~
r'/[a-zA-Z][^\s]*', # Absolute paths (start with /) r'/[a-zA-Z][^\s]*', # Absolute paths (start with /)
r'\$[^\n]+', # Shell commands r'\$[^\n]+', # Shell commands
] ]
@ -135,7 +135,7 @@ def transform_vocabulary(response_text: str, session_id: str = "", model: str =
transformed = transformed.replace(f"\x00PRESERVE{i}\x00", original) transformed = transformed.replace(f"\x00PRESERVE{i}\x00", original)
# Add random opening interjection (25% chance) # Add random opening interjection (25% chance)
# Configurable via SPONGEBOB_INTERJECTION_CHANCE env var(0.0-1.0) # Configurable via SPONGEBOB_INTERJECTION_CHANCE env var (0.0-1.0)
interjection_chance = float(os.environ.get("SPONGEBOB_INTERJECTION_CHANCE", "0.25")) interjection_chance = float(os.environ.get("SPONGEBOB_INTERJECTION_CHANCE", "0.25"))
if random.random() < interjection_chance: if random.random() < interjection_chance:
@ -151,7 +151,7 @@ def transform_vocabulary(response_text: str, session_id: str = "", model: str =
) )
if not already_interjected: if not already_interjected:
# Prepend interjection with newline separator # Prepend interjection with space separator
transformed = f"{interjection} {transformed}" transformed = f"{interjection} {transformed}"
logger.info(f"[spongebob-vocab] Prepended interjection: {interjection}") logger.info(f"[spongebob-vocab] Prepended interjection: {interjection}")
@ -162,6 +162,6 @@ def register(ctx):
"""Register the transform hook with Hermes.""" """Register the transform hook with Hermes."""
ctx.register_hook("transform_llm_output", transform_vocabulary) ctx.register_hook("transform_llm_output", transform_vocabulary)
logger.info("[spongebob-vocab] Registered transform_llm_output hook") logger.info("[spongebob-vocab] Registered transform_llm_output hook")
__all__ = ["transform_vocabulary", "register"] __all__ = ["transform_vocabulary", "register"]