> ## Documentation Index
> Fetch the complete documentation index at: https://ikun.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Dalle

## 先决条件

您需要安装 `openai` 库。

```bash theme={null}
pip install openai
```

设置 `OPENAI_API_KEY` 环境变量。

```bash theme={null}
export OPENAI_API_KEY=****
```

## 示例

下面的代理将使用 DALL-E 根据文本提示生成图像。

```python cookbook/tools/dalle_tools.py theme={null}
from agno.agent import Agent
from agno.tools.dalle import DalleTools

# 使用 DALL-E 工具创建 Agent
agent = Agent(tools=[DalleTools()], name="DALL-E Image Generator")

# 示例 1：使用默认设置生成基本图像
agent.print_response("Generate an image of a futuristic city with flying cars and tall skyscrapers", markdown=True)

# 示例 2：使用自定义设置生成图像
custom_dalle = Dalle(model="dall-e-3", size="1792x1024", quality="hd", style="natural")

agent_custom = Agent(
    tools=[custom_dalle],
    name="Custom DALL-E Generator",
    show_tool_calls=True,
)

agent_custom.print_response("Create a panoramic nature scene showing a peaceful mountain lake at sunset", markdown=True)
```

## Toolkit 参数

| 参数        | 类型    | 默认值           | 描述                                                         |
| --------- | ----- | ------------- | ---------------------------------------------------------- |
| `model`   | `str` | `"dall-e-3"`  | 要使用的 DALL-E 模型                                             |
| `n`       | `int` | `1`           | 要生成的图像数量                                                   |
| `size`    | `str` | `"1024x1024"` | 图像尺寸 (256x256, 512x512, 1024x1024, 1792x1024, 或 1024x1792) |
| `quality` | `str` | `"standard"`  | 图像质量 (standard 或 hd)                                       |
| `style`   | `str` | `"vivid"`     | 图像风格 (vivid 或 natural)                                     |
| `api_key` | `str` | `None`        | 用于身份验证的 OpenAI API 密钥                                      |

## Toolkit 函数

| 函数               | 描述         |
| ---------------- | ---------- |
| `generate_image` | 根据文本提示生成图像 |

## 开发者资源

* 查看 [Tools](https://github.com/agno-agi/agno/blob/main/libs/agno/agno/tools/dalle.py)
* 查看 [Cookbook](https://github.com/agno-agi/agno/blob/main/cookbook/tools/dalle_tools.py)
