Skip to main content
Use the built-in DalleTools to generate images using DALL-E. It provides image generation capabilities for your agent.

Installation

Install the required dependencies:
pip install openai

Setup

Set your OpenAI API key as an environment variable:
export OPENAI_API_KEY=sk-...

Usage

Import and use the DalleTools:
import os
from hypertic.agents import Agent
from hypertic.models import OpenAIChat
from hypertic.tools import DalleTools

# Create DALL-E tools instance
dalle = DalleTools(
    model="dall-e-3",
    size="1024x1024",
    quality="standard",
    style="vivid",
)

model = OpenAIChat(model="gpt-4o")
agent = Agent(
    model=model,
    tools=[dalle],
)

response = agent.run("Generate a picture of a dog playing with a ball")
print(response.content)

Configuration Options

Configure DalleTools with these parameters:
  • model - DALL-E model to use (e.g., “dall-e-3”)
  • size - Image size (e.g., “1024x1024”, “1792x1024”, “1024x1792”)
  • quality - Image quality (“standard” or “hd”)
  • style - Image style (“vivid” or “natural”)

Example

import os
import asyncio
from hypertic.agents import Agent
from hypertic.models import OpenAIChat
from hypertic.tools import DalleTools

# Create DALL-E tools instance
dalle = DalleTools(
    model="dall-e-3",
    size="1024x1024",
    quality="standard",
    style="vivid",
)

model = OpenAIChat(model="gpt-4o")
agent = Agent(
    model=model,
    tools=[dalle],
)

async def main():
    async for event in agent.astream("Generate a picture of a dog playing with a ball"):
        if event.type == "content":
            print(event.content, end="", flush=True)
        elif event.type == "tool_calls":
            print(f"\nTool Calls: {event.tool_calls}")
        elif event.type == "tool_outputs":
            print(f"\nTool Outputs: {event.tool_outputs}")

asyncio.run(main())
The agent can use DalleTools to generate images based on natural language descriptions.