Skip to content

Commit 792c94a

Browse files
committed
Add RemovePunctuationConverter
1 parent 80c07b3 commit 792c94a

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

aisploit/converter/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
KEYBOARD_NEIGHBORS_QWERTZ,
88
)
99
from .no_op import NoOpConverter
10+
from .remove_punctuation import RemovePunctuationConverter
1011
from .sequence import SequenceConverter
1112

1213
__all__ = [
@@ -17,5 +18,6 @@
1718
"KEYBOARD_NEIGHBORS_QWERTY",
1819
"KEYBOARD_NEIGHBORS_QWERTZ",
1920
"NoOpConverter",
21+
"RemovePunctuationConverter",
2022
"SequenceConverter",
2123
]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import string
2+
from ..core import BaseConverter
3+
4+
5+
class RemovePunctuationConverter(BaseConverter):
6+
def _convert(self, prompt: str) -> str:
7+
translator = str.maketrans('', '', string.punctuation)
8+
return prompt.translate(translator)

examples/converter.ipynb

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@
2828
"import os\n",
2929
"import textwrap\n",
3030
"from dotenv import load_dotenv\n",
31-
"from aisploit.converter import Base64Converter, KeyboardTypoConverter, JoinConverter, GenderConverter\n",
31+
"from aisploit.converter import (\n",
32+
" Base64Converter,\n",
33+
" KeyboardTypoConverter,\n",
34+
" JoinConverter,\n",
35+
" GenderConverter,\n",
36+
" RemovePunctuationConverter,\n",
37+
")\n",
3238
"from aisploit.models import ChatOpenAI\n",
3339
"\n",
3440
"load_dotenv()"
@@ -177,6 +183,38 @@
177183
"\n",
178184
"display(Markdown(converted_prompt.to_string()))"
179185
]
186+
},
187+
{
188+
"cell_type": "markdown",
189+
"metadata": {},
190+
"source": [
191+
"## RemovePunctuationConverter"
192+
]
193+
},
194+
{
195+
"cell_type": "code",
196+
"execution_count": 7,
197+
"metadata": {},
198+
"outputs": [
199+
{
200+
"data": {
201+
"text/markdown": [
202+
"Hello world How are you"
203+
],
204+
"text/plain": [
205+
"<IPython.core.display.Markdown object>"
206+
]
207+
},
208+
"metadata": {},
209+
"output_type": "display_data"
210+
}
211+
],
212+
"source": [
213+
"converter = RemovePunctuationConverter()\n",
214+
"converted_prompt = converter.convert(\"Hello, world! How are you?\")\n",
215+
"\n",
216+
"display(Markdown(converted_prompt.to_string()))"
217+
]
180218
}
181219
],
182220
"metadata": {

0 commit comments

Comments
 (0)