跳转到主要内容

文档索引

获取完整文档索引: https://docs.crewai.com.cn/llms.txt

在深入了解之前,请使用此文件来浏览所有可用页面。

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