You need to enable JavaScript to run this app.
AI 数据湖服务

AI 数据湖服务

复制全文
图片编辑
图片生成编辑(豆包seedream系列模型)
复制全文
图片生成编辑(豆包seedream系列模型)

算子介绍

描述

图像生成处理器(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]] | None
  • 输出列:
  • 生成结果:pa.array[list[str] | None](每行输出图片 URL 或 base64 字符串列表,取决于 response_format

注意与前提

细分项

注意与前提

费用

调用算子前,您需先了解使用算子时的模型调用费用,详情请参见大模型调用计费

鉴权(API Key)

调用算子前,您需要先生成算子调用的API Key,并建议将API Key配置为环境变量,便于更安全地调用算子,详情请参见获取 API Key 并配置

BaseURL

调用算子前,您需要先根据您当前使用的LAS服务所在地域,了解算子调用的BaseURL,用于配置算子调用路径参数取值。
详情请参见获取 Base URL,下文中的调用示例仅作为参考,实际调用时需替换为您对应地域的路径取值。

Daft 调用

算子参数

输入

输入列名

说明

prompts

文本提示词。类型为 str。用于文生图/图生图(结合 reference_images)。

reference_images

参考图(可选)。用于图生图。支持 None / str / list[str]

  • None:文生图
  • str:单张参考图 URL
  • list[str]:多张参考图 URL

输出

返回每行生成的图片列表:

  • 类型:list[str] | None
  • response_format="url" 时,list[str] 里是图片 URL
  • response_format="b64_json" 时,list[str] 里是 base64 字符串
  • 单行失败/跳过时返回 None

参数

如参数没有默认值,则为必填参数

参数名称

类型

默认值

描述

model

str

必填

模型名称,例如

  • doubao-seedream-4.5 / doubao-seedream-4.0

version

int or None

None

模型版本号,例如 251128

api_key

str or None

None

鉴权 token(仅 token 本体,不含 Bearer 前缀)。不传则从环境变量 LAS_API_KEY/API_KEY 读取

sequential_image_generation

str

disabled

单图/组图控制:

  • disabled:单图
  • auto:组图

sequential_image_generation_options

dict or None

None

组图参数(仅 auto 生效),例如:{"max_images": 3}

watermark

bool

true

是否添加“AI生成”水印

size

str

2048x2048

输出尺寸,例如 2048x20482K(以服务端实际支持为准)

response_format

str

url

返回格式:url / b64_json

optimize_prompt_options

dict or None

None

提示词优化配置(仅部分版本支持),例如:{"mode": "standard"}

request_timeout

int

1200

单次请求超时时间(秒)

max_concurrency

int

100

每个进程最大并发数

调用示例

下面的代码展示了如何使用 Daft + las_udfDoubaoImageGenerate 做批量推理,覆盖文生图 + 图生图两种场景。

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                           │
    # ╰────────────────────────────────────────┴────────────────────────────────┴────────────────────────────────╯
        
最近更新时间:2026.02.10 15:51:19
这个页面对您有帮助吗?
有用
有用
无用
无用