Skip to content

FEAT: add superscript converter - #818

Merged
Roman Lutz (romanlutz) merged 22 commits into
microsoft:mainfrom
paulinek13:feat/528/superscript_converter
Jun 14, 2025
Merged

FEAT: add superscript converter#818
Roman Lutz (romanlutz) merged 22 commits into
microsoft:mainfrom
paulinek13:feat/528/superscript_converter

Conversation

@paulinek13

@paulinek13 Paulina Kalicka (paulinek13) commented Mar 21, 2025

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Paulina Kalicka (paulinek13) marked this pull request as ready for review March 23, 2025 16:02
@paulinek13 Paulina Kalicka (paulinek13) changed the title [DRAFT] FEAT: add superscript converter SuperscriptConverter [DRAFT] FEAT: add superscript converter Mar 23, 2025
@romanlutz

Copy link
Copy Markdown
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
Copy Markdown
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
Paulina Kalicka (paulinek13) marked this pull request as draft March 24, 2025 18:27
@paulinek13

Copy link
Copy Markdown
Contributor Author

Roman Lutz (@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
Copy Markdown
Contributor

Is this idea actually any good?

I love it! What do others think? @rlundeen2 Nina Chikanov (@nina-msft) Eugenia Kim (@eugeniavkim) jbolor21 Justin Song (@jsong468) Bashir Partovi (@bashirpartovi)

@romanlutz

Copy link
Copy Markdown
Contributor

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

@paulinek13

Copy link
Copy Markdown
Contributor Author

Sure thing! I'm on it 😃

@paulinek13

Paulina Kalicka (paulinek13) commented Jun 10, 2025

Copy link
Copy Markdown
Contributor Author

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

@paulinek13
Paulina Kalicka (paulinek13) marked this pull request as ready for review June 10, 2025 20:19
@paulinek13 Paulina Kalicka (paulinek13) changed the title [DRAFT] FEAT: add superscript converter FEAT: add superscript converter Jun 10, 2025
Comment thread tests/unit/converter/test_superscript_converter.py
@romanlutz
Roman Lutz (romanlutz) merged commit 4c2a424 into microsoft:main Jun 14, 2025
Sarayu Poddutoori (Sarayu-code) pushed a commit to Sarayu-code/PyRIT that referenced this pull request Jul 11, 2025
@paulinek13
Paulina Kalicka (paulinek13) deleted the feat/528/superscript_converter branch November 6, 2025 16:25
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