#error in importing Configuration from openai

18 messages · Page 1 of 1 (latest)

fallow goblet
#

can anyone help me figure out the error I get using gpt3.5 turbo model " The requested module 'openai' does not provide an export named 'Configuration' "

lucid silo
#

Can you post your code or request?

#

Is that a python error from importing the library?

lucid silo
fallow goblet
#

this is the error i got

fallow goblet
#

im given a task to integrate openai API to a frontend project

lucid silo
#

According to the documentation this is how you use the package:


import OpenAI from "openai";

const openai = new OpenAI();

async function main() {
  const completion = await openai.chat.completions.create({
    messages: [{ role: "system", content: "string" }],
    model: "gpt-3.5-turbo",
  });

  console.log(completion.choices[0]);
}

main();
#

What exactly are you trying to do?

fallow goblet
#

` import express from "express";
import * as dotenv from 'dotenv';
import cors from 'cors';
import { Configuration , OpenAIApi } from "openai";

dotenv.config();

const configuration = new Configuration({
apikey: process.env.OPENAI_API_KEY,
});

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

app.get('/', async (req, res) => {
res.status(200).send({
message: 'What up '
})
});

app.post('/', async (req, res) => {
try {
const prompt = req.body.prompt;
const response = await OpenAI.openai.chat.completions.create({
model: "gpt-3.5-turbo",
messages: [
{
"role": "user",
"content": "Create a list of 8 questions for an interview with a science fiction author."
}
],
temperature: 0,
max_tokens: 3000,
top_p: 1,
frequency_penalty: 0.5,
presence_penalty: 0,
});

    res.status(200).send({
        bot: response.data.choices[0].text
    })
} catch (error) {
    console.log(error);
    res.status(500).send({error})
}

});

app.listen(5000, ()=> console.log('server is running on port http://localhost:5000'));
`

lucid silo
#

What the error is telling me is that OpenAI doesn’t have a “Configuration” object. I recommend looking at the documentation and using their provided code.

fallow goblet
#

for authorization it is given as import { Configuration, OpenAIApi } from "openai"; const configuration = new Configuration({ organization: "org-9Joj1yrJcrIMRgrMWdQgS5kc", apiKey: process.env.OPENAI_API_KEY, }); const openai = new OpenAIApi(configuration); const response = await openai.listEngines();

#

this is what i'm doing ig

lucid silo
#

It’s possible there’s an issue with the package, or many it’s been updated. Can OpenAIApi be successfully imported, or do neither work?

#

Try importing just OpenAIApi. If it doesn’t work, check that your package is installed correctly, otherwise it might be outdated.

fallow goblet
#

yeah OpenAIApi also doesn't work

#

yeah the code was outdated