Dalle

Prerequisites

You need to install the openai library.

1uv pip install openai

Set the OPENAI_API_KEY environment variable.

1export OPENAI_API_KEY=****

Example

The following agent will use DALL-E to generate an image based on a text prompt.

1from kern.agent import Agent
2from kern.tools.dalle import DalleTools
3
4# Create an Agent with the DALL-E tool
5agent = Agent(tools=[DalleTools()], name="DALL-E Image Generator")
6
7# Example 1: Generate a basic image with default settings
8agent.print_response("Generate an image of a futuristic city with flying cars and tall skyscrapers", markdown=True)
9
10# Example 2: Generate an image with custom settings
11custom_dalle = Dalle(model="dall-e-3", size="1792x1024", quality="hd", style="natural")
12
13agent_custom = Agent(
14 tools=[custom_dalle],
15 name="Custom DALL-E Generator",
16 )
17
18agent_custom.print_response("Create a panoramic nature scene showing a peaceful mountain lake at sunset", markdown=True)

Toolkit Params

ParameterTypeDefaultDescription
modelstr"dall-e-3"The DALL-E model to use
enable_create_imageboolTrueEnable the create image functionality
nint1Number of images to generate
sizestr"1024x1024"Image size (256x256, 512x512, 1024x1024, 1792x1024, or 1024x1792)
qualitystr"standard"Image quality (standard or hd)
stylestr"vivid"Image style (vivid or natural)
api_keystrNoneThe OpenAI API key for authentication
allboolFalseEnable all functionality when set to True

Toolkit Functions

FunctionDescription
generate_imageGenerates an image based on a text prompt

Developer Resources