跳转到主要内容
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 工具是否已正确添加到智能体的工具列表中。