跳转到内容

使用 DALL-E 生成图像

CrewAI 支持与 OpenAI 的 DALL-E 集成,使你的 AI agents 能够在任务中生成图像。 本指南将带你完成在 CrewAI 项目中设置和使用 DALL-E 工具的过程。

  • 已安装 crewAI(最新版本)
  • 具备可访问 DALL-E 的 OpenAI API key
  1. 导入 DALL-E 工具
    from crewai_tools import DallETool
  2. 将 DALL-E 工具添加到你的 agent 配置中
    @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 工具添加到 agent 后,它就可以根据文本提示生成图像。该工具 会返回生成图像的 URL,你可以将其用于 agent 的输出,或传递给其他 agents 进行进一步处理。

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 工具的 agent 将能够生成图像,并在回复中提供一个 URL。然后你可 以下载该图像。

DALL-E 图像
  1. 在图像生成提示词中尽量具体,以获得最佳效果。
  2. 考虑生成时间 - 图像生成可能需要一些时间,因此在任务规划中要考虑这一点。
  3. 遵守使用政策 - 在生成图像时始终遵守 OpenAI 的使用政策。
  1. 检查 API 访问 - 确保你的 OpenAI API key 具备访问 DALL-E 的权限。
  2. 版本兼容性 - 确保你使用的是最新版本的 crewAI 和 crewai-tools。
  3. 工具配置 - 验证 DALL-E 工具是否已正确添加到 agent 的工具列表中。