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