Source code for pyrit.prompt_converter.base64_converter
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import base64
from pyrit.models import PromptDataType
from pyrit.prompt_converter import PromptConverter, ConverterResult
[docs]
class Base64Converter(PromptConverter):
[docs]
async def convert_async(self, *, prompt: str, input_type: PromptDataType = "text") -> ConverterResult:
"""
Simple converter that just base64 encodes the prompt
"""
if not self.input_supported(input_type):
raise ValueError("Input type not supported")
string_bytes = prompt.encode("utf-8")
encoded_bytes = base64.b64encode(string_bytes)
return ConverterResult(output_text=encoded_bytes.decode("utf-8"), output_type="text")