Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT: introduce word-level converter #847

Open
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

paulinek13
Copy link
Contributor

@paulinek13 paulinek13 commented Mar 31, 2025

Description

This PR introduces a new base class called WordLevelConverter, which simplifies the creation of word-level converters by providing a reusable foundation that standardizes word selection for transformation and reduces code duplication across similar converters.

The key benefit is that one only needs to implement the specific word transformation logic (convert_word_async) while the base class handles word selection, iteration, and final result.

Word selection strategies/modes

The base class supports various word selection modes through the select_word_indices util function:

  • all - convert/transform every word in the prompt (default)
  • keywords - only specific words provided in a keywords list
  • random - a random subset of words based on a specified percentage
  • regex - words that match a regular expression pattern
  • custom - only specifically chosen word indices

List of refactored prompt converters

The following converters have been refactored to use the new base class:

  • BinaryConverter
  • CharSwapGenerator
  • EmojiConverter
  • LeetspeakConverter
  • ROT13Converter
  • StringJoinConverter
  • TextToHexConverter
  • UnicodeReplacementConverter

Note: I'm not sure if all the prompt converters that I've refactored should be word-level based, or if there are other converters that haven't been refactored that would benefit from this base class.

Related: #818 (comment)


Tests and Documentation

Updated docs and tests

@romanlutz romanlutz requested a review from rlundeen2 March 31, 2025 19:53
@paulinek13 paulinek13 force-pushed the feat/add_word_level_converter branch 2 times, most recently from 863fc37 to 8d88759 Compare April 12, 2025 18:06
@paulinek13 paulinek13 force-pushed the feat/add_word_level_converter branch from 8d88759 to 12b79e1 Compare April 12, 2025 18:09
@paulinek13 paulinek13 marked this pull request as ready for review April 12, 2025 18:11
@paulinek13 paulinek13 changed the title [DRAFT] FEAT: introduce word-level converter FEAT: introduce word-level converter Apr 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant