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

'openai' does not provide an export named 'Configuration' 🥲 #68

Open
scipiodev opened this issue Aug 17, 2023 · 5 comments
Open

'openai' does not provide an export named 'Configuration' 🥲 #68

scipiodev opened this issue Aug 17, 2023 · 5 comments

Comments

@scipiodev
Copy link

scipiodev commented Aug 17, 2023

Hey everyone, I'm following along and I'm at 38:00 on the video but when I try to run the server I get this in the Terminal (see screenshot).

Can anyone advise what I can do to fix this? 🙏 Thanks!!

Problem
@Utkarsh-1104
Copy link

Utkarsh-1104 commented Sep 10, 2023

This is because in the newer version of chatgpt they have removed Configuration from openai module.
The solution is quite simple, just dont import Configurations and it'll work fine.

image

@XanderThrows
Copy link

Utkarsh is correct although to completely fix this do:
const openai = new OpenAI({
apiKey: 'My API Key'
});

@scipiodev
Copy link
Author

Thanks for letting me know!

@Preetham71
Copy link

Utkarsh is correct although to completely fix this do: const openai = new OpenAI({ apiKey: 'My API Key' });

Bro it is showing the error as OpenAIError: The OPENAI_API_KEY environment variable is missing or empty; either provide it, or instantiate the OpenAI client with an apiKey option, like new OpenAI({ apiKey: 'My API Key' }).

@Splitwolf1
Copy link

Splitwolf1 commented Jan 19, 2024

Try installing axios in root folder(open_ai folder )
(npm install axios )
then implement these changes bellow on your code

import express from 'express';
import * as dotenv from 'dotenv';
import cors from 'cors';
import axios from 'axios';

dotenv.config();

const apiKey = process.env.OPENAI_API_KEY;
const openaiEndpoint = 'https://api.openai.com/v1/chat/completions';

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

app.get('/', async (req, res) => {
res.status(200).send({
message: 'Hello from CodeX!',
});
});

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

const response = await axios.post(
  openaiEndpoint,
  {
    model: 'gpt-3.5-turbo-1106',
    response_format: { type: 'json_object' },
    messages: [
      { role: 'system', content: 'You are a helpful assistant designed to output JSON.' },
      { role: 'user', content: prompt },
    ],
  },
  {
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${apiKey}`,
    },
  }
);

const output = response.data.choices[0].message.content;
res.status(200).send({
  bot: output,
});

} catch (error) {
console.log(error);
res.status(500).send(error || 'Something went wrong');
}
});

app.listen(5001, () => console.log('AI server started on http://localhost:5001'));

bot

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

5 participants