adrianhajdin / project_threejs_ai

https://jsmastery.pro
923 stars 278 forks source link

Error : Could not load data:image/png;base64,undefined: undefined #67

Closed Shaheer5 closed 2 weeks ago

Shaheer5 commented 3 months ago

Problem

I think I have not properly migrated to OpenAI v4, I could use some help make it work.

the errors I'm getting are:

Code

`// this is created using v4 of OpenAI API

import express from "express"; import * as dotenv from "dotenv"; import OpenAI from "openai";

dotenv.config();

const router = express.Router();

const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY, });

router.route("/").get((req, res) => { res.status(200).json({ message: "Hello from DALL-E routes" }); });

// posting image to front-end app router.route("/").post(async (req, res) => { try { const { prompt } = req.body; const aiResponse = await openai.images.generate({ model: "dall-e-3", prompt, n: 1, size: "1024x1024", response_format: "b64_json", }); const image = aiResponse.data.data[0].b64_json; res.status(200).json({ photo: image }); } catch (error) { console.error(error); res.status(500).json({ message: "Something went wrong" }); } });

export default router; `

Mohamed-Ismail-Dev commented 2 months ago

Have you solved the error? if yes, Help me i got the same error . I changed my code to the above given but it don't work

Shaheer5 commented 2 months ago

Not working for me as well. It say open ai budget limit exceeded. even on a fresh account free trail

Reck1618 commented 2 months ago

Fix: The issue is how you extract the image from the response body. In your dalle.routes.js Change this line -> const image = aiResponse.data.data[0].b64_json; To this line -> const image = aiResponse.data[0].b64_json;

Reck1618 commented 2 months ago

Not working for me as well. It say open ai budget limit exceeded. even on a fresh account free trail

Also, you will have to add balance to your openAI account, because openAI has stopped giving free credit to new accounts.