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:
parent
d97e28467d
commit
150178bc12
1 changed files with 35 additions and 35 deletions
70
__init__.py
70
__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"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue