Skip to content

FEAT: add superscript converter #818

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

Merged
merged 22 commits into from
Jun 14, 2025

Conversation

paulinek13
Copy link
Contributor

@paulinek13 paulinek13 commented Mar 21, 2025

Description

This PR aims to resolve #528 by adding a new converter: SuperscriptConverter.

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

@romanlutz
Copy link
Contributor

@paulinek13 I suppose we can continue this one now that #847 is in! It might be much simpler now 🙂

@paulinek13
Copy link
Contributor Author

Sure thing! I'm on it 😃

@paulinek13
Copy link
Contributor Author

paulinek13 commented Jun 10, 2025

The SuperscriptConverter and its tests are now updated, I just have a few questions:

@paulinek13 paulinek13 marked this pull request as ready for review June 10, 2025 20:19
@paulinek13 paulinek13 changed the title [DRAFT] FEAT: add superscript converter FEAT: add superscript converter Jun 10, 2025
@romanlutz romanlutz merged commit 4c2a424 into Azure:main Jun 14, 2025
19 checks passed
Sarayu-code pushed a commit to Sarayu-code/PyRIT that referenced this pull request Jul 11, 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.

FEAT superscript converter
2 participants