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

[DRAFT] FEAT: add superscript converter #818

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

paulinek13
Copy link
Contributor

@paulinek13 paulinek13 commented Mar 21, 2025

Description

This PR aims to resolve #528 by adding a new converter: SuperscriptConverter which supports various modes for conversion.

class SuperscriptConverter(PromptConverter):
    """
    Converts the input text to superscript text. Supports various modes for conversion.

    Supported modes:
    - 'all': Converts all words. The default mode.
    - 'alternate': Converts every other word. Configurable.
    - 'random': Converts a random selection of words based on a percentage.

    Note:
        This converter leaves characters that do not have a superscript equivalent unchanged.
    """

Tests and Documentation

I've added unit tests for the converter

@paulinek13
Copy link
Contributor Author

While working on this, I came up with a few additional options/modes for conversion:

  • pattern-based: convert only words matching a specific regex pattern
  • keyword-based: convert only words from a list of keywords
  • toggle mode: conversion for marked sections only, e.g., "This is normal but [[this will be superscript]] and this is normal again"

What do you think about these? Would any of them be valuable to add?

As for subscripts, I believe we could implement this by adding an optional boolean parameter to the SuperscriptConverter class. What do you think?

@paulinek13 paulinek13 marked this pull request as ready for review March 23, 2025 16:02
@paulinek13 paulinek13 changed the title [DRAFT] FEAT: add superscript converter SuperscriptConverter [DRAFT] FEAT: add superscript converter Mar 23, 2025
@romanlutz
Copy link
Contributor

You can see I tagged you and this PR in #822 because I think a lot of these patterns can be generalized so that we don't have to reinvent the wheel over and over again for various converters. That said, if you want to leave that for a future issue/PR that's totally fine!

@paulinek13
Copy link
Contributor Author

a lot of these patterns can be generalized so that we don't have to reinvent the wheel over and over again for various converters

I totally agree! It 100% makes sense to generalize the common patterns first, so I think I’ll wait with this PR until that’s done

@paulinek13 paulinek13 marked this pull request as draft March 24, 2025 18:27
@paulinek13
Copy link
Contributor Author

@romanlutz

I have an idea: maybe we could add a base class for all the simple word-level converters, like WordLevelPromptConverter? I did some prototyping here: paulinek13/PyRIT/tree/idea/word_level_converter

So the usage would look like this:

    keyword_converter = SuperscriptConverter(
        mode="keywords",
        keywords=['test', 'conversion']
    )

And in place of SuperscriptConverter we could place any similar converter (word-level based), for example ROT13Converter, which I actually refactored so that it's based on the WordLevelPromptConverter class and now it's as simple as:

class ROT13Converter(WordLevelPromptConverter):
    async def convert_word_async(self, word: str) -> str:
        return codecs.encode(word, "rot13")

The concept's commit: /commit/be8a5d972fb4e7568e11954d9c531d063766d07d
Is this idea actually any good?

@romanlutz
Copy link
Contributor

Is this idea actually any good?

I love it! What do others think? @rlundeen2 @nina-msft @eugeniavkim @jbolor21 @jsong468 @bashirpartovi

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.

FEAT superscript converter
2 participants