ImageGenerationModel 图库¶
本节包含在 distilabel
中实现的现有 ImageGenerationModel
子类。
image_generation
¶
AsyncImageGenerationModel
¶
异步 ImageGenerationModels
的抽象类,以受益于每个 LLM 实现的异步功能。此类旨在由每个 ImageGenerationModel
子类化,并且需要实现方法 agenerate
以提供响应的异步生成。
属性
名称 | 类型 | 描述 |
---|---|---|
_event_loop |
AbstractEventLoop
|
用于异步生成响应的事件循环。 |
源代码位于 src/distilabel/models/image_generation/base.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
|
generate_parameters
property
¶
返回 agenerate
方法的参数。
返回
类型 | 描述 |
---|---|
list[Parameter]
|
包含 |
generate_parsed_docstring
cached
property
¶
返回 agenerate
方法的解析后的文档字符串。
返回
类型 | 描述 |
---|---|
文档字符串
|
|
agenerate(input, num_generations=1, **kwargs)
abstractmethod
async
¶
从提供的输入生成图像。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
input
|
str
|
从中生成图像的输入文本。 |
必需 |
num_generations
|
int
|
要生成的图像数量。默认为 |
1
|
返回
类型 | 描述 |
---|---|
list[dict[str, Any]]
|
包含一个字典的列表,该字典包含生成的图像列表。 |
源代码位于 src/distilabel/models/image_generation/base.py
_agenerate(inputs, num_generations=1, **kwargs)
async
¶
用于并发地为输入列表生成图像的内部函数。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
inputs
|
list[str]
|
要为其生成图像的输入列表。 |
必需 |
num_generations
|
int
|
每个输入要生成的代数。 |
1
|
**kwargs
|
Any
|
用于生成的其他 kwargs。 |
{}
|
返回
类型 | 描述 |
---|---|
list[list[dict[str, Any]]]
|
包含每个输入的生成的列表。 |
源代码位于 src/distilabel/models/image_generation/base.py
generate(inputs, num_generations=1, **kwargs)
¶
异步生成图像列表的方法,同步返回输出,等待发送到 agenerate
的每个输入的图像。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
inputs
|
list[str]
|
要为其生成图像的输入列表。 |
必需 |
num_generations
|
int
|
每个输入要生成的代数。 |
1
|
**kwargs
|
Any
|
用于生成的其他 kwargs。 |
{}
|
返回
类型 | 描述 |
---|---|
list[list[dict[str, Any]]]
|
包含每个输入的图像的列表。 |
源代码位于 src/distilabel/models/image_generation/base.py
__del__()
¶
当对象被删除时关闭事件循环。
源代码位于 src/distilabel/models/image_generation/base.py
InferenceEndpointsImageGeneration
¶
基类: InferenceEndpointsBaseClient
, AsyncImageGenerationModel
Inference Endpoint 图像生成实现,运行异步 API 客户端。
属性
名称 | 类型 | 描述 |
---|---|---|
model_id |
Optional[str]
|
用于 ImageGenerationModel 的模型 ID,可在 Hugging Face Hub 中找到,它将用于解析 Serverless Inference Endpoints API 请求的基本 URL。默认为 |
endpoint_name |
Optional[RuntimeParameter[str]]
|
用于 LLM 的 Inference Endpoint 的名称。默认为 |
endpoint_namespace |
Optional[RuntimeParameter[str]]
|
用于 LLM 的 Inference Endpoint 的命名空间。默认为 |
base_url |
Optional[RuntimeParameter[str]]
|
用于 Inference Endpoints API 请求的基本 URL。 |
api_key |
Optional[RuntimeParameter[SecretStr]]
|
用于验证对 Inference Endpoints API 请求的 API 密钥。 |
图标
:hugging
示例
从文本提示生成图像
from distilabel.models.image_generation import InferenceEndpointsImageGeneration
igm = InferenceEndpointsImageGeneration(model_id="black-forest-labs/FLUX.1-schnell", api_key="api.key")
igm.load()
output = igm.generate_outputs(
inputs=["a white siamese cat"],
)
# [{"images": ["iVBORw0KGgoAAAANSUhEUgA..."]}]
源代码位于 src/distilabel/models/image_generation/huggingface/inference_endpoints.py
agenerate(input, negative_prompt=None, height=None, width=None, num_inference_steps=None, guidance_scale=None, num_generations=1)
async
¶
使用 huggingface_hub.AsyncInferenceClient.text_to_image
从文本提示生成图像。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
input
|
str
|
从中生成图像的提示。 |
必需 |
negative_prompt
|
Optional[str]
|
图像生成的可选负面提示。默认为 None。 |
None
|
height
|
Optional[float]
|
要生成的图像的高度(以像素为单位)。 |
None
|
width
|
Optional[float]
|
要生成的图像的宽度(以像素为单位)。 |
None
|
num_inference_steps
|
Optional[float]
|
去噪步骤的数量。更多的去噪步骤通常会以较慢的推理速度为代价带来更高质量的图像。 |
None
|
guidance_scale
|
Optional[float]
|
更高的 guidance scale 鼓励生成与文本 |
None
|
num_generations
|
int
|
要生成的图像数量。默认为 |
1
|
返回
类型 | 描述 |
---|---|
list[dict[str, Any]]
|
包含一个字典的列表,该字典包含一个列表,其中包含作为 base64 字符串的图像。 |
源代码位于 src/distilabel/models/image_generation/huggingface/inference_endpoints.py
OpenAIImageGeneration
¶
基类: OpenAIBaseClient
, AsyncImageGenerationModel
OpenAI 图像生成实现,运行异步 API 客户端。
属性
名称 | 类型 | 描述 |
---|---|---|
model |
str
|
用于 ImageGenerationModel 的模型名称,例如 "dall-e-3" 等。支持的模型可以在这里找到。 |
base_url |
Optional[RuntimeParameter[str]]
|
用于 OpenAI API 请求的基本 URL。默认为 |
api_key |
Optional[RuntimeParameter[SecretStr]]
|
用于验证对 OpenAI API 请求的 API 密钥。默认为 |
max_retries |
RuntimeParameter[int]
|
在失败之前,重试 API 请求的最大次数。默认为 |
timeout |
RuntimeParameter[int]
|
等待 API 响应的最大时间(秒)。默认为 |
图标
:simple-openai
示例
从文本提示生成图像
from distilabel.models.image_generation import OpenAIImageGeneration
igm = OpenAIImageGeneration(model="dall-e-3", api_key="api.key")
igm.load()
output = igm.generate_outputs(
inputs=["a white siamese cat"],
size="1024x1024",
quality="standard",
style="natural",
)
# [{"images": ["iVBORw0KGgoAAAANSUhEUgA..."]}]
源代码位于 src/distilabel/models/image_generation/openai.py
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 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
agenerate(input, num_generations=1, quality='standard', response_format='url', size=None, style=None)
async
¶
使用 OpenAI 异步客户端为给定输入生成 num_generations
图像。图像是 base64 字符串表示形式。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
input
|
str
|
所需图像的文本描述。 |
必需 |
num_generations
|
int
|
要生成的图像数量。必须介于 1 和 10 之间。对于 |
1
|
quality
|
Optional[Literal['standard', 'hd']]
|
将生成的图像的质量。 |
'standard'
|
response_format
|
Optional[Literal['url', 'b64_json']]
|
返回生成的图像的格式。必须是 |
'url'
|
size
|
Optional[Literal['256x256', '512x512', '1024x1024', '1792x1024', '1024x1792']]
|
生成的图像的大小。对于 |
None
|
style
|
Optional[Literal['vivid', 'natural']]
|
生成的图像的风格。必须是 |
None
|
返回
类型 | 描述 |
---|---|
list[dict[str, Any]]
|
包含一个字典的列表,该字典包含生成的图像列表。 |