pyrit.prompt_target.OpenAIDALLETarget#

class OpenAIDALLETarget(image_size: Literal['256x256', '512x512', '1024x1024'] = '1024x1024', num_images: int = 1, dalle_version: Literal['dall-e-2', 'dall-e-3'] = 'dall-e-2', quality: Literal['standard', 'hd'] = 'standard', style: Literal['natural', 'vivid'] = 'natural', *args, **kwargs)[source]#

Bases: OpenAITarget

The Dalle3Target takes a prompt and generates images This class initializes a DALL-E image target

__init__(image_size: Literal['256x256', '512x512', '1024x1024'] = '1024x1024', num_images: int = 1, dalle_version: Literal['dall-e-2', 'dall-e-3'] = 'dall-e-2', quality: Literal['standard', 'hd'] = 'standard', style: Literal['natural', 'vivid'] = 'natural', *args, **kwargs)[source]#

Initialize the DALL-E target with specified parameters.

Parameters:
  • model_name (str, Optional) – The name of the model.

  • endpoint (str, Optional) – The target URL for the OpenAI service.

  • api_key (str, Optional) – The API key for accessing the Azure OpenAI service. Defaults to the AZURE_OPENAI_CHAT_KEY environment variable.

  • headers (str, Optional) – Headers of the endpoint (JSON).

  • use_aad_auth (bool, Optional) – When set to True, user authentication is used instead of API Key. DefaultAzureCredential is taken for https://cognitiveservices.azure.com/.default . Please run az login locally to leverage user AuthN.

  • api_version (str, Optional) – The version of the Azure OpenAI API. Defaults to “2024-06-01”.

  • max_requests_per_minute (int, Optional) – Number of requests the target can handle per minute before hitting a rate limit. The number of requests sent to the target will be capped at the value provided.

  • image_size (Literal["256x256", "512x512", "1024x1024"], Optional) – The size of the generated images. Defaults to “1024x1024”.

  • num_images (int, Optional) – The number of images to generate. Defaults to 1. For DALL-E-2, this can be between 1 and 10. For DALL-E-3, this must be 1.

  • dalle_version (Literal["dall-e-2", "dall-e-3"], Optional) – The version of DALL-E to use. Defaults to “dall-e-2”.

  • quality (Literal["standard", "hd"], Optional) – The quality of the generated images. Only applicable for DALL-E-3. Defaults to “standard”.

  • style (Literal["natural", "vivid"], Optional) – The style of the generated images. Only applicable for DALL-E-3. Defaults to “natural”.

  • *args – Additional positional arguments to be passed to AzureOpenAITarget.

  • **kwargs – Additional keyword arguments to be passed to AzureOpenAITarget.

Raises:
  • ValueError – If num_images is not 1 for DALL-E-3.

  • ValueError – If num_images is less than 1 or greater than 10 for DALL-E-2.

Methods

__init__([image_size, num_images, ...])

Initialize the DALL-E target with specified parameters.

dispose_db_engine()

Dispose DuckDB database engine to release database connections and resources.

get_identifier()

is_json_response_supported()

Indicates that this target supports JSON response format.

is_response_format_json(request_piece)

Checks if the response format is JSON and ensures the target supports it.

send_prompt_async(**kwargs)

Sends a normalized prompt async to the prompt target.

set_system_prompt(*, system_prompt, ...[, ...])

Sets the system prompt for the prompt target.

Attributes

api_key_environment_variable: str#
endpoint_environment_variable: str#
is_json_response_supported() bool[source]#

Indicates that this target supports JSON response format.

model_name_environment_variable: str#
async send_prompt_async(**kwargs)#

Sends a normalized prompt async to the prompt target.