#error in importing Configuration from openai
18 messages · Page 1 of 1 (latest)
Can you post your code or request?
Is that a python error from importing the library?
It would be easier to help it I could see what you are doing
this is the error i got
im working in nodejs
im given a task to integrate openai API to a frontend project
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?
Explore developer resources, tutorials, API docs, and dynamic examples to get the most out of OpenAI's platform.
` 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'));
`
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.
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