Code Monkey home page Code Monkey logo

Comments (9)

SarangMarkandey avatar SarangMarkandey commented on June 11, 2024 1

if anyone has done the same project where in the api actually works, please help me out...

Replace dalleRoutes.js with this code, and make sure you have the open ai API credits

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.send('Hello from DALL-E!')
}) 

router.route('/').post(async (req, res) => {
    try {
        const { prompt } = req.body;
        const aiResponse = await openai.images.generate({
            prompt,
            n: 1,
            size: '1024x1024',
            response_format: 'b64_json',
        });
        
        // console.log("aiResponse :  ",aiResponse)
        const image = aiResponse.data[0].b64_json;
        res.status(200).json({photo: image});
        
    } catch (error) {
        console.log(error);
        res.status(500).send(error?.response.data.error.message)
    }
})

export default router;

from project_ai_mern_image_generation.

HimanshuRahul avatar HimanshuRahul commented on June 11, 2024 1

@SarangMarkandey thanks for helping, took some time to debug, but I can finally run the api. For anyone facing the issue, please first update your openai in package.json to "openai": "^4.0.0". Then npm install, and then paste the above code in dalleRoutes.js
Please refer this link to update from v3 to v4 openai/openai-node#217

from project_ai_mern_image_generation.

SETHEAD avatar SETHEAD commented on June 11, 2024

if anyone has done the same project where in the api actually works, please help me out...

Replace dalleRoutes.js with this code, and make sure you have the open ai API credits

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.send('Hello from DALL-E!')
}) 

router.route('/').post(async (req, res) => {
    try {
        const { prompt } = req.body;
        const aiResponse = await openai.images.generate({
            prompt,
            n: 1,
            size: '1024x1024',
            response_format: 'b64_json',
        });
        
        // console.log("aiResponse :  ",aiResponse)
        const image = aiResponse.data[0].b64_json;
        res.status(200).json({photo: image});
        
    } catch (error) {
        console.log(error);
        res.status(500).send(error?.response.data.error.message)
    }
})

export default router;

hello, can i connect with you on discord or some other platform if its fine by you?

from project_ai_mern_image_generation.

SarangMarkandey avatar SarangMarkandey commented on June 11, 2024

if anyone has done the same project where in the api actually works, please help me out...

Replace dalleRoutes.js with this code, and make sure you have the open ai API credits

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.send('Hello from DALL-E!')
}) 

router.route('/').post(async (req, res) => {
    try {
        const { prompt } = req.body;
        const aiResponse = await openai.images.generate({
            prompt,
            n: 1,
            size: '1024x1024',
            response_format: 'b64_json',
        });
        
        // console.log("aiResponse :  ",aiResponse)
        const image = aiResponse.data[0].b64_json;
        res.status(200).json({photo: image});
        
    } catch (error) {
        console.log(error);
        res.status(500).send(error?.response.data.error.message)
    }
})

export default router;

hello, can i connect with you on discord or some other platform if its fine by you?

sure

from project_ai_mern_image_generation.

euortiz avatar euortiz commented on June 11, 2024

I've done all of that and I'm still getting TypeError: Failed to fetch. I have 5$ credits, do you have some idea why I'm getting this ?

from project_ai_mern_image_generation.

SarangMarkandey avatar SarangMarkandey commented on June 11, 2024

I've done all of that and I'm still getting TypeError: Failed to fetch. I have 5$ credits, do you have some idea why I'm getting this ?

can you share your code?

from project_ai_mern_image_generation.

SETHEAD avatar SETHEAD commented on June 11, 2024

I've done all of that and I'm still getting TypeError: Failed to fetch. I have 5$ credits, do you have some idea why I'm getting this ?

same :((

did you find any solution for that??

from project_ai_mern_image_generation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.