Skip to content
CrewAI 文档版本 跟随上游 源快照 34ad23a1 更新于 2026-10-18

使用 DALL-E 生成图像

了解如何在你的 CrewAI 项目中使用 DALL-E 进行 AI 驱动的图像生成

CrewAI 支持与 OpenAI 的 DALL-E 集成,使你的 AI 智能体能够生成图像作为其任务的一部分。本指南将引导你了解如何在 CrewAI 项目中设置和使用 DALL-E 工具。

前置条件

  • 已安装 crewAI(最新版本)
  • 具有 DALL-E 访问权限的 OpenAI API 密钥

设置 DALL-E 工具

Import the DALL-E tool

python
from crewai_tools import DallETool

Add the DALL-E tool to your agent configuration

python
@agent
def researcher(self) -> Agent:
    return Agent(
        config=self.agents_config['researcher'],
        tools=[SerperDevTool(), DallETool()],  # Add DallETool to the list of tools
        allow_delegation=False,
        verbose=True
    )

使用 DALL-E 工具

将 DALL-E 工具添加到智能体后,它就可以根据文本提示词生成图像。该工具将返回生成图像的 URL,可用于智能体的输出,或传递给其他智能体以进行进一步处理。

示例智能体配置

yaml
role: >
    LinkedIn Profile Senior Data Researcher
goal: >
    Uncover detailed LinkedIn profiles based on provided name {name} and domain {domain}
    Generate a Dall-e image based on domain {domain}
backstory: >
    You're a seasoned researcher with a knack for uncovering the most relevant LinkedIn profiles.
    Known for your ability to navigate LinkedIn efficiently, you excel at gathering and presenting
    professional information clearly and concisely.

预期输出

配备 DALL-E 工具的智能体将能够生成图像并在其响应中提供 URL。然后你可以下载该图像。

DALL-E Image

最佳实践

  1. 在图像生成提示词中要具体明确,以获得最佳结果。
  2. 考虑生成时间 - 图像生成可能需要一些时间,因此请将其纳入任务规划。
  3. 遵守使用政策 - 生成图像时始终遵守 OpenAI 的使用政策。

故障排查

  1. 检查 API 访问权限 - 确保你的 OpenAI API 密钥具有 DALL-E 访问权限。
  2. 版本兼容性 - 检查你使用的是最新版本的 crewAI 和 crewai-tools。
  3. 工具配置 - 验证 DALL-E 工具已正确添加到智能体的工具列表中。

BytesRouter 是社区翻译站点,所有译文仅供参考,一切以官方英文原文为准。