How to generate images using Dall-E
Using the DALL-E Tool in crewAI
crewAI now supports integration with OpenAI's DALL-E, allowing your AI agents to generate images as part of their tasks. This guide will walk you through how to set up and use the DALL-E tool in your crewAI projects.
Prerequisites
- crewAI installed (latest version)
- OpenAI API key with access to DALL-E
Setting Up the DALL-E Tool
To use the DALL-E tool in your CrewAI project, follow these steps:
1. Import the DALL-E tool:
```python
from crewai_tools import DallETool
```
2. Add 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
)
```
Using the DALL-E Tool
Once you've added the DALL-E tool to your agent, it can generate images based on text prompts. The tool will return a URL to the generated image, which can be used in the agent's output or passed to other agents for further processing.
Example usage within a task:
researcher:
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.
The agent with the DALL-E tool will be able to generate the image and provide a URL in its response. You can then download the image.
Best Practices
1. Be specific in your image generation prompts to get the best results.
2. Remember that image generation can take some time, so factor this into your task planning.
3. Always comply with OpenAI's usage policies when generating images.
Troubleshooting
If you encounter issues:
1. Ensure your OpenAI API key has access to DALL-E.
2. Check that you're using the latest version of crewAI and crewai-tools.
3. Verify that the DALL-E tool is correctly added to the agent's tool list.