pyrit.prompt_target.OpenAIImageTarget#
- class OpenAIImageTarget(image_size: Literal['256x256', '512x512', '1024x1024', '1536x1024', '1024x1536'] = '1024x1024', quality: Literal['standard', 'hd', 'low', 'medium', 'high'] | None = None, style: Literal['natural', 'vivid'] | None = None, *args, **kwargs)[source]#
Bases:
OpenAITargetA target for image generation using OpenAI’s image models.
- __init__(image_size: Literal['256x256', '512x512', '1024x1024', '1536x1024', '1024x1536'] = '1024x1024', quality: Literal['standard', 'hd', 'low', 'medium', 'high'] | None = None, style: Literal['natural', 'vivid'] | None = None, *args, **kwargs)[source]#
Initialize the image 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 OPENAI_IMAGE_API_KEY environment variable.
headers (str, Optional) – Headers of the endpoint (JSON).
use_entra_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.
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”.
quality (Literal["standard", "hd", "low", "medium", "high"], Optional) – The quality of the generated images. Different models support different quality settings. For DALL-E-3, there’s “standard” and “hd”. For newer models, there are “low”, “medium”, and “high”. Default is to not specify.
style (Literal["natural", "vivid"], Optional) – The style of the generated images. Default is to not specify.
*args – Additional positional arguments to be passed to AzureOpenAITarget.
**kwargs – Additional keyword arguments to be passed to AzureOpenAITarget.
httpx_client_kwargs (dict, Optional) – Additional kwargs to be passed to the httpx.AsyncClient() constructor. For example, to specify a 3 minutes timeout: httpx_client_kwargs={“timeout”: 180}
Methods
__init__([image_size, quality, style])Initialize the image target with specified parameters.
dispose_db_engine()Dispose database engine to release database connections and resources.
get_identifier()Indicates that this target supports JSON response format.
is_response_format_json(message_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_model_name(*, model_name)Set the model name for this target.
set_system_prompt(*, system_prompt, ...[, ...])Sets the system prompt for the prompt target.
Attributes
ADDITIONAL_REQUEST_HEADERSsupported_converters