OpenAi API 错误:“配置不是构造函数”

问题描述 投票:0回答:1

我正在尝试构建一个生成图像的不和谐机器人,但我遇到了这个问题。我正在关注 YouTube 上的教程,我希望有人帮助我解决这个问题。

`const { SlashCommandBuilder, EmbedBuilder} = require(`discord.js`);
const { Configuration, OpenAIApi } = require("openai");

const configuration = new Configuration({
  apiKey: 'My Key'
});
const openai = new OpenAIApi(configuration);`


# I think this is a tough one since its a command building integrated with openai Api
javascript discord discord.js bots openai-api
1个回答
0
投票

您尝试的代码适用于 OpenAI Node.js SDK <

v4
,但您使用的是 >=
v4

如果您使用 OpenAI Node.js SDK >=

v4
,以下是正确的初始化:

import OpenAI from "openai";
const openai = new OpenAI(
  apiKey: "sk-xxxxxxxxxxxxxxxxxxxxxxxx"
);
© www.soinside.com 2019 - 2024. All rights reserved.