Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dream example not working #1

Open
multivac61 opened this issue Jan 6, 2023 · 7 comments
Open

Dream example not working #1

multivac61 opened this issue Jan 6, 2023 · 7 comments

Comments

@multivac61
Copy link

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

@RomanHyde
Copy link

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 ?

@multivac61
Copy link
Author

Unfortunately, no 😞

@kiwi2299
Copy link

kiwi2299 commented Feb 4, 2023

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?

@JHannema
Copy link

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

@ArB1t3r
Copy link

ArB1t3r commented Apr 2, 2023

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

@sebastian031093
Copy link

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

@BenRoc1979
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants