使用 DALL-E 生成图像
CrewAI 支持与 OpenAI 的 DALL-E 集成,使你的 AI agents 能够在任务中生成图像。 本指南将带你完成在 CrewAI 项目中设置和使用 DALL-E 工具的过程。
- 已安装 crewAI(最新版本)
- 具备可访问 DALL-E 的 OpenAI API key
设置 DALL-E 工具
Section titled “设置 DALL-E 工具”- 导入 DALL-E 工具from crewai_tools import DallETool
- 将 DALL-E 工具添加到你的 agent 配置中@agentdef researcher(self) -> Agent:return Agent(config=self.agents_config['researcher'],tools=[SerperDevTool(), DallETool()], # Add DallETool to the list of toolsallow_delegation=False,verbose=True)
使用 DALL-E 工具
Section titled “使用 DALL-E 工具”当你把 DALL-E 工具添加到 agent 后,它就可以根据文本提示生成图像。该工具 会返回生成图像的 URL,你可以将其用于 agent 的输出,或传递给其他 agents 进行进一步处理。
agent 配置示例
Section titled “agent 配置示例”role: > LinkedIn Profile Senior Data Researchergoal: > 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。然后你可 以下载该图像。
- 在图像生成提示词中尽量具体,以获得最佳效果。
- 考虑生成时间 - 图像生成可能需要一些时间,因此在任务规划中要考虑这一点。
- 遵守使用政策 - 在生成图像时始终遵守 OpenAI 的使用政策。
- 检查 API 访问 - 确保你的 OpenAI API key 具备访问 DALL-E 的权限。
- 版本兼容性 - 确保你使用的是最新版本的 crewAI 和 crewai-tools。
- 工具配置 - 验证 DALL-E 工具是否已正确添加到 agent 的工具列表中。