# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import random
from pyrit.models import PromptDataType
from pyrit.prompt_converter import PromptConverter, ConverterResult
[docs]
class EmojiConverter(PromptConverter):
emoji_dict = {
"a": ["π
", "π
°οΈ", "π°"],
"b": ["π
", "π
±οΈ", "π±"],
"c": ["π
", "π
²", "π²"],
"d": ["π
", "π
³", "π³"],
"e": ["π
", "π
΄", "π΄"],
"f": ["π
", "π
΅", "π΅"],
"g": ["π
", "π
Ά", "πΆ"],
"h": ["π
", "π
·", "π·"],
"i": ["π
", "π
Έ", "πΈ"],
"j": ["π
", "π
Ή", "πΉ"],
"k": ["π
", "π
Ί", "πΊ"],
"l": ["π
", "π
»", "π»"],
"m": ["π
", "π
Ό", "πΌ"],
"n": ["π
", "π
½", "π½"],
"o": ["π
", "π
ΎοΈ", "πΎ"],
"p": ["π
", "π
ΏοΈ", "πΏ"],
"q": ["π
", "π", "π
"],
"r": ["π
‘", "π", "π
"],
"s": ["π
’", "π", "π
"],
"t": ["π
£", "π", "π
"],
"u": ["π
€", "π", "π
"],
"v": ["π
₯", "π
", "π
"],
"w": ["π
¦", "π", "π
"],
"x": ["π
§", "π", "π
"],
"y": ["π
¨", "π", "π
"],
"z": ["π
©", "π", "π
"],
}
[docs]
async def convert_async(self, *, prompt: str, input_type: PromptDataType = "text") -> ConverterResult:
"""
Converts English text to randomly chosen circle or square character emojis.
Inspired by https://github.com/BASI-LABS/parseltongue/blob/main/src/utils.ts
"""
if not self.input_supported(input_type):
raise ValueError("Input type not supported")
prompt = prompt.lower()
result = []
for char in prompt:
if char in EmojiConverter.emoji_dict:
result.append(random.choice(EmojiConverter.emoji_dict[char]))
else:
result.append(char)
ret_text = "".join(result)
return ConverterResult(output_text=ret_text, output_type="text")