from pathlib import Path
from agno.agent import Agent
from agno.tools.dalle import DalleTools
from agno.utils.media import download_image
agent = Agent(tools=[DalleTools()], name="DALL-E 图片生成器")
agent.print_response(
"生成一张未来城市,有飞行汽车和高耸摩天大楼的图片",
markdown=True,
)
custom_dalle = DalleTools(
model="dall-e-3", size="1792x1024", quality="hd", style="natural"
)
agent_custom = Agent(
tools=[custom_dalle],
name="自定义 DALL-E 生成器",
show_tool_calls=True,
)
response = agent_custom.run(
"创作一幅全景自然风景,描绘日落时宁静的山间湖泊",
markdown=True,
)
if response.images:
download_image(
url=response.images[0].url,
save_path=Path(__file__).parent.joinpath("tmp/nature.jpg"),
)
创建虚拟环境
打开 Terminal
并创建一个 python 虚拟环境。
python3 -m venv .venv
source .venv/bin/activate
设置你的 API 密钥
export OPENAI_API_KEY=xxx # DALL-E 图片生成所需
安装库
pip install -U openai agno
运行 Agent
python cookbook/tools/dalle_tools.py