- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个简单的 react 应用程序来使用 openai api 生成图像,如下所示。
`
import logo from './logo.svg';
import './App.css';
import { useState } from "react";
const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
function App() {
const [userPrompt, setUserPrompt] = useState("")
const [imageUrl, setImageUrl] = useState("")
const generateImage = async () => {
const imageParameters = {
prompt: userPrompt,
n:1,
size: "256x256",
}
const response = await openai.createImage(imageParameters);
const urlData = response.data.data[0].url;
console.log("urlData =",urlData);
setImageUrl(urlData);
}
return (
<div className="App">
{
imageUrl
? <img src={imageUrl} className="image" alt="ai thing" />
: <img src={logo} className="image" alt="logo" />
}
<p>Generate a unique image using DALL·E</p>
<p>What do you want to see?</p>
<input
placeholder='A sunset on the Sydney Opera House'
onChange={(e) => setUserPrompt(e.target.value)}
/>
<button onClick={() => generateImage()}>Generate</button>
</div>
);
}
export default App;
`
API KEY 在 .env 文件中并且是正确的。但是,当我单击生成按钮时,它会在控制台上抛出错误,如下所示:
我尝试使用 DALL-E API 创建一个 react 应用程序,以使用此 guide 生成图像.在进行 API 调用/请求后,我无法收到(图片)响应消息。
最佳答案
这里是一个 ES6 NodeJs 示例,它可以工作并保存一个 PNG 文件。要让它工作,请在 package.json 之上添加“type”:“module”。对 OpenAi 的请求会返回一组指向 png 文件的 url。 createImage中的“n”是数组中图片的数量。
import { Configuration, OpenAIApi } from "openai";
import http from "https"; // or 'https' for https:// URLs
import fs from "fs";
const configuration = new Configuration({
apiKey: OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
const response = await openai.createImage({
prompt: "A cute baby sea otter",
n: 1,
size: "1024x1024",
});
const file = fs.createWriteStream("test.png");
const request = http.get(response.data.data[0].url, function (response) {
response.pipe(file);
file.on("finish", () => {
file.close();
console.log("Download Done!");
});
});
关于node.js - OPENAI API 从 openai.createImage() 创建图像响应给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74419871/
我正在尝试使用 opencv v 2.1 创建图像,但出现此错误: image=cv.CreateImage((w,h),no_of_bits,channels) AttributeError: 'm
所以我注意到 DropzoneJS 有以下配置选项:createImageThumbnails ( http://www.dropzonejs.com/#config-createImageThumb
我已经使用 AWS 的 Java API 一段时间了,但不知何故,我找不到如何删除使用 CreateImage 请求创建的快照。 此请求将为您提供包含图像 ID 的图像。当您想要删除图像时,您可以根据
我正在构建一个 Android 应用程序,但出现以下错误: java.lang.IllegalStateException E/AndroidRuntime: at android.graphics.
此代码在 for 循环中的 Image.createImage(path) 上给我一个 NullPointerException。怎么可能? 我使用一个数组作为名称,一个数组作为路径,一个 Array
我有以下代码,作为游戏的一部分每 10 毫秒运行一次: private void gameRender() { if(dbImage == null) { //crea
我正在使用 Swing 创建一个 UI,我想在 JLabel 中显示图像。我使用的代码如下: JLabel label = new JLabel(new ImageIcon(ImageIO.read
我有一个简单的 react 应用程序来使用 openai api 生成图像,如下所示。 ` import logo from './logo.svg'; import './App.css'; imp
我有一个简单的 react 应用程序来使用 openai api 生成图像,如下所示。 ` import logo from './logo.svg'; import './App.css'; imp
我正在尝试使用 LWUIT 创建启动屏幕。我想要一个表单来加载并显示文本和图像 5 秒钟,然后继续下一个表单。我有代码,但无法显示图像。类和图像一起存储在同一个包中。相反,它显示一个错误。 java.
我正在研究 Java 分形程序。在我的设计中,我想实现一个特定的 ImageProducer 类,该类在调用 startProduction(ImageConsumer) 时在后台工作线程中计算像素。
这是我的代码。我无法从此 vector 对象创建图像。 Hashtable metaData = new Hashtable(); Vector Ad = IADView.getBannerAdDat
这是我的任务 async function generateImage() { try { const response = await openai.createImage({
这是我的任务 async function generateImage() { try { const response = await openai.createImage({
我是一名优秀的程序员,十分优秀!