fireship-io/javascript-course

Dream example not working

Opened this issue · 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

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 ?

Unfortunately, no 😞

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?

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

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

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'));
`

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.