I have been facing an issue in my code while trying to run the chatbot using OpenAI API .
I can’t understand why it’s showing like this.
I am attaching my code and the error I am facing for reference.
import { config } from "dotenv";
config();
import { Configuration, OpenAIApi } from "openai";
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
async function chat(input) {
const messages = [{ role: "user", content: input }];
const response = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: messages,
temperature: 0,
});
return response.data.choices[0].message.content;
}
const question = "What is the capital of France";
chat(question)
.then((response) => console.log(response))
.catch((error) => console.error(error));