prefect_openai.image
Module for generating and configuring OpenAI images.
Classes
ImageModel
Bases: Block
A block that contains config for an OpenAI Image Model. Learn more in the OpenAPI Image generation docs
Attributes:
Name | Type | Description |
---|---|---|
openai_credentials |
OpenAICredentials
|
The credentials used to authenticate with OpenAI. |
size |
Literal['256x256', '512x512', '1024x1024']
|
The size of the image to generate. |
n |
int
|
The number of images to generate. |
response_format |
Literal['url', 'b64_json']
|
The format of the image to generate. |
Example
Load a configured block:
from prefect_openai import ImageModel
image_model = ImageModel.load("BLOCK_NAME")
Source code in prefect_openai/image.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
|
Attributes
logger: Logger
property
Returns a logger based on whether the ImageModel is called from within a flow or task run context. If a run context is present, the logger property returns a run logger. Else, it returns a default logger labeled with the class's name.
Returns:
Type | Description |
---|---|
Logger
|
The run logger or a default logger with the class's name. |
Functions
submit_prompt
async
Submits a prompt for the model to generate an image. Learn more in the OpenAPI Image generation docs
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt |
str
|
The prompt to use for the image. |
required |
**acreate_kwargs |
Dict[str, Any]
|
Additional keyword arguments to pass
to |
{}
|
Returns:
Type | Description |
---|---|
OpenAIObject
|
The OpenAIObject containing the image and associated metadata. |
Example
Create an OpenAI Image given a prompt:
from prefect_openai import ImageModel
image_model = ImageModel.load("BLOCK_NAME")
image_model.submit_prompt(prompt="A prompt for an image.")
Source code in prefect_openai/image.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
|