Skip to main content

Dall-E 工具

¥Dall-E Tool

Dall-E 工具允许你的代理使用 OpenAI 的 Dall-E 图片生成工具创建图片。

¥The Dall-E tool allows your agent to create images using OpenAI's Dall-E image generation tool.

设置

¥Setup

你需要一个 OpenAI API 密钥,你可以从 OpenAI 网站 获取,然后将 OPENAI_API_KEY 环境变量设置为你刚刚创建的密钥。

¥You will need an OpenAI API Key which you can get from the OpenAI web site and then set the OPENAI_API_KEY environment variable to the key you just created.

要使用 Dall-E Tool,你需要安装 LangChain OpenAI 集成包:

¥To use the Dall-E Tool you need to install the LangChain OpenAI integration package:

npm install @langchain/openai @langchain/core
/* eslint-disable no-process-env */
import { DallEAPIWrapper } from "@langchain/openai";

const tool = new DallEAPIWrapper({
n: 1, // Default
model: "dall-e-3", // Default
apiKey: process.env.OPENAI_API_KEY, // Default
});

const imageURL = await tool.invoke("a painting of a cat");

console.log(imageURL);

API Reference:

¥Related