javascript-course icon indicating copy to clipboard operation
javascript-course copied to clipboard

Dream example not working

Open multivac61 opened this issue 3 years ago • 7 comments

I am following along the js course and am unable to get the OpenAI example running.

Here are the steps I ran

  1. Pulled the newest source code via git
  2. cd into dream
  3. run npm i to install the packages
  4. I add my OpenAI API key to a .env file
  5. Running node server.js and navigating to http://localhost:8080/ results in a text saying Cannot GET /
  6. Running npm run dev points me over to http://localhost:3000/ where I can see the correct HTML
  7. Posting a prompt to OpenAI yields an error:
image

multivac61 avatar Jan 06 '23 15:01 multivac61

When I run it, it will run on a different port for me too, so I updated the references to port 8080 to match. On the demo version, I'm getting an empty string error though. I've asked in the discord and someone responded to say that I should stringify the code but it has been.

Have you managed to get around this issue since @multivac61 ?

RomanHyde avatar Jan 20 '23 15:01 RomanHyde

Unfortunately, no 😞

multivac61 avatar Jan 20 '23 19:01 multivac61

I have my server.js app running in port 5172 and the npm server running in port 5173 at the same time and it worked properly, just had to have both instances running. Maybe it is not intended to work like this?

kiwi2299 avatar Feb 04 '23 06:02 kiwi2299

You can choose to move the public files to a public folder and add app.use(express.static('public')) to server.js. Then run the app usingnode server.js 8080

JHannema avatar Mar 27 '23 13:03 JHannema

You need to run both node server.js & npm run dev for this to work properly, open up the front end webpage and see if it works

ArB1t3r avatar Apr 02 '23 15:04 ArB1t3r

Hands up bro might be the resquest to openIA change here you can see how to do that.

this can be some one of your problems .

`import * as dotenv from 'dotenv'; dotenv.config();

import OpenAI from 'openai';

const configuration = { apiKey: process.env.OPENIA_KEY, };

const openai = new OpenAI(configuration); //console.log(openai.images);

import express from 'express'; import cors from 'cors';

const app = express(); app.use(cors()); app.use(express.json());

app.post('/dream', async (req, res) => { const prompt = req.body.prompt;

const aiResponse = await openai.images.generate({ model: 'dall-e-3', prompt: prompt, }); console.log(image.data); const image = aiResponse.data.data[0].url; res.send({ image }); });

app.listen(8080, () => console.log('make art on http://localhost:8080/dream')); `

sebastian031093 avatar Jan 21 '24 19:01 sebastian031093

Even with the code from sebastian031093, it's not working. I get this: "(node:17176) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead." but then I see the "make art on http://localhost:8080/dream" but that url gives me the "Cannot get /" tried running npm run dev at the same time, no change.

BenRoc1979 avatar Feb 26 '24 20:02 BenRoc1979