Comments (9)
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.
@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.
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.
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.
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.
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.
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)
- server responded with 500 error when i generate post and try to add to home page but photo is not showing on home page HOT 5
- CORS Error HOT 2
- help me to find a solution of the given erro... SyntaxError: Unexpected token 'B', "Billing ha"... is not valid JSON. HOT 11
- Getting error when I am clicking generate image "type error : failed to fetch " HOT 21
- Whenever I try to share API generated image to the home page, it gives me "POST http://localhost:8080/api/v1/post 500 (Internal Server Error) handleSubmit @ CreatePost.jsx:23" error even after giving "Success" alert. HOT 3
- Failed to load resource: the server responded with a status of 500 (Internal Server Error) HOT 4
- invalid image URL ,trouble in rendering image
- err in createpost page when i click generate than err occurs tht invalid api HOT 2
- Openai HOT 1
- Error HOT 4
- Error HOT 1
- unexpected end of json
- Error occured HOT 7
- Anyone can solve this.. HOT 7
- POST http://localhost:8080/api/v1/post 500 (Internal Server Error) HOT 2
- Image error HOT 1
- [nodemon] app crashed - waiting for file changes before starting... HOT 4
- The solutions for major 4 Issues (#57, #56, #54 and # 59) HOT 2
- Solution Provided for : issue #2 File Saver npm Package not working after hosting
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from project_ai_mern_image_generation.