主题
使用 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 DallEToolAdd 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。然后你可以下载该图像。

最佳实践
- 在图像生成提示词中要具体明确,以获得最佳结果。
- 考虑生成时间 - 图像生成可能需要一些时间,因此请将其纳入任务规划。
- 遵守使用政策 - 生成图像时始终遵守 OpenAI 的使用政策。
故障排查
- 检查 API 访问权限 - 确保你的 OpenAI API 密钥具有 DALL-E 访问权限。
- 版本兼容性 - 检查你使用的是最新版本的 crewAI 和 crewai-tools。
- 工具配置 - 验证 DALL-E 工具已正确添加到智能体的工具列表中。