跳转到主要内容
CrewAI 支持与 OpenAI 的 DALL-E 集成,允许您的 AI 代理作为其任务的一部分生成图像。本指南将引导您完成在 CrewAI 项目中设置和使用 DALL-E 工具的过程。

先决条件

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

设置 DALL-E 工具

1

导入 DALL-E 工具

from crewai_tools import DallETool
2

将 DALL-E 工具添加到您的代理配置中

@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,该 URL 可用于代理的输出或传递给其他代理进行进一步处理。

代理配置示例

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 工具是否已正确添加到代理的工具列表中。