pyrit.prompt_target.TextTarget#

class TextTarget(*, text_stream: ~typing.IO[str] = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]#

Bases: PromptTarget

The TextTarget takes prompts, adds them to memory and writes them to io which is sys.stdout by default.

This can be useful in various situations, for example, if operators want to generate prompts but enter them manually.

__init__(*, text_stream: ~typing.IO[str] = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>) None[source]#

Initialize the TextTarget.

Parameters:

text_stream (IO[str]) – The text stream to write prompts to. Defaults to sys.stdout.

Methods

__init__(*[, text_stream])

Initialize the TextTarget.

cleanup_target()

Target does not require cleanup.

dispose_db_engine()

Dispose database engine to release database connections and resources.

get_identifier()

Get an identifier dictionary for this prompt target.

import_scores_from_csv(csv_file_path)

Import message pieces and their scores from a CSV file.

send_prompt_async(*, message)

Asynchronously write a message to the text stream.

set_model_name(*, model_name)

Set the model name for this target.

Attributes

supported_converters

A list of PromptConverters that are supported by the prompt target.

async cleanup_target()[source]#

Target does not require cleanup.

import_scores_from_csv(csv_file_path: Path) list[MessagePiece][source]#

Import message pieces and their scores from a CSV file.

Parameters:

csv_file_path (Path) – The path to the CSV file containing scores.

Returns:

A list of message pieces imported from the CSV.

Return type:

list[MessagePiece]

async send_prompt_async(*, message: Message) list[Message][source]#

Asynchronously write a message to the text stream.

Parameters:

message (Message) – The message object to write to the stream.

Returns:

An empty list (no response expected).

Return type:

list[Message]

supported_converters: list#

A list of PromptConverters that are supported by the prompt target. An empty list implies that the prompt target supports all converters.