图像生成处理器(doubao-seedream)
prompt 即可生成图像reference_images(1 张或多张参考图)+ prompt,在参考图基础上生成图像sequential_image_generation="auto" + sequential_image_generation_options={"max_images": N} 一次生成多张图response_format="url":返回图片链接(链接生成后 24 小时内失效)response_format="b64_json":返回 base64 字符串optimize_prompt_options={"mode": "standard" | "fast"}doubao-seedream-4.0(version: 250828)doubao-seedream-4.5(version: 251128)prompts):pa.array[str]reference_images):pa.array[str | list[str]] | Nonepa.array[list[str] | None](每行输出图片 URL 或 base64 字符串列表,取决于 response_format)细分项 | 注意与前提 |
|---|---|
费用 | 调用算子前,您需先了解使用算子时的模型调用费用,详情请参见大模型调用计费。 |
鉴权(API Key) | 调用算子前,您需要先生成算子调用的API Key,并建议将API Key配置为环境变量,便于更安全地调用算子,详情请参见获取 API Key 并配置。 |
BaseURL | 调用算子前,您需要先根据您当前使用的LAS服务所在地域,了解算子调用的BaseURL,用于配置算子调用路径参数取值。 |
输入列名 | 说明 |
|---|---|
prompts | 文本提示词。类型为 |
reference_images | 参考图(可选)。用于图生图。支持
|
返回每行生成的图片列表:
list[str] | Noneresponse_format="url" 时,list[str] 里是图片 URLresponse_format="b64_json" 时,list[str] 里是 base64 字符串None如参数没有默认值,则为必填参数
参数名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
model | str | 必填 | 模型名称,例如
|
version | int or None | None | 模型版本号,例如 |
api_key | str or None | None | 鉴权 token(仅 token 本体,不含 |
sequential_image_generation | str | disabled | 单图/组图控制:
|
sequential_image_generation_options | dict or None | None | 组图参数(仅 |
watermark | bool | true | 是否添加“AI生成”水印 |
size | str | 2048x2048 | 输出尺寸,例如 |
response_format | str | url | 返回格式: |
optimize_prompt_options | dict or None | None | 提示词优化配置(仅部分版本支持),例如: |
request_timeout | int | 1200 | 单次请求超时时间(秒) |
max_concurrency | int | 100 | 每个进程最大并发数 |
下面的代码展示了如何使用 Daft + las_udf 对 DoubaoImageGenerate 做批量推理,覆盖文生图 + 图生图两种场景。
import daft from daft import col from daft.las.functions.ark_llm.doubao_image_generate import DoubaoImageGenerate from daft.las.functions.udf import las_udf import os if os.getenv("DAFT_RUNNER", "native") == "ray": import logging import ray def configure_logging(): logging.basicConfig( level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", datefmt="%Y-%m-%d %H:%M:%S.%s".format(), ) logging.getLogger("tracing.span").setLevel(logging.WARNING) logging.getLogger("daft_io.stats").setLevel(logging.WARNING) logging.getLogger("DaftStatisticsManager").setLevel(logging.WARNING) logging.getLogger("DaftFlotillaScheduler").setLevel(logging.WARNING) logging.getLogger("DaftFlotillaDispatcher").setLevel(logging.WARNING) ray.init(dashboard_host="0.0.0.0", runtime_env={"worker_process_setup_hook": configure_logging}) daft.set_runner_ray() daft.set_execution_config(min_cpu_per_task=0) if __name__ == "__main__": # 运行前需配置环境变量: # - LAS_BASE_URL, 从 LAS 服务页面上创建获取 # - LAS_INFERENCE_TYPE=image_generate # - LAS_IMAGE_GENERATE_ENDPOINT=/api/v1/online/image/generate(可选,通常默认即可) # - LAS_API_KEY 或 API_KEY, 从 LAS 服务页面上创建获取 tos_dir_url = os.getenv("TOS_DIR_URL", "las-cn-beijing-public-online.tos-cn-beijing.volces.com") samples = { "prompt": [ "生成一张长城的照片,真实摄影风格", # 文生图 "保持构图不变,把图片风格改成水彩画风格", # 图生图(配合 reference_images) None, # 异常行示例:该行输出 None,不影响其它行 ], "reference_images": [ None, f"https://{tos_dir_url}/public/shared_image_dataset/seedream_test_image.png", None, ], } df = daft.from_pydict(samples) df = df.with_column( "images", las_udf( DoubaoImageGenerate, construct_args={ "model": "doubao-seedream-4.5", "version": 251128, "response_format": "url", "watermark": False, "sequential_image_generation": "disabled", "size": "2048x2048", }, batch_size=3, concurrency=3, num_gpus=0, )(col("prompt"), col("reference_images")), ) df.show() # 输出示例(每次大模型推理结果可能不同) # ╭────────────────────────────────────────┬────────────────────────────────┬────────────────────────────────╮ # │ prompt ┆ reference_images ┆ images │ # │ --- ┆ --- ┆ --- │ # │ String ┆ String ┆ List[String] │ # ╞════════════════════════════════════════╪════════════════════════════════╪════════════════════════════════╡ # │ 生成一张长城的照片,真实摄影风格 ┆ None ┆ [https://ark-content-generati… │ # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ # │ 保持构图不变,把图片风格改成水彩画风格 ┆ https://ark-project.tos-cn-be… ┆ [https://ark-content-generati… │ # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ # │ None ┆ None ┆ None │ # ╰────────────────────────────────────────┴────────────────────────────────┴────────────────────────────────╯