我一直得到错误“TypeError:Cannot read properties of undefined(阅读'create')”在shell中,下面是我的代码:
const { SlashCommandBuilder } = require('discord.js');
const openai = require('openai');
openai.apiKey = 'i put my api key here';
module.exports = {
data: new SlashCommandBuilder()
.setName('ama')
.setDescription('ask me anything!')
.addStringOption(option =>
option.setName('prompt')
.setDescription('type any question...')),
async execute(interaction) {
try {
const prompt = interaction.options.getString('prompt');
const gptResponse = await openai.Completion.create({
engine: "text-davinci-003",
prompt: `answer the following question that is asked.\n\
ChatGPT: Hello, how are you?\n\
${interaction.user.username}: ${prompt}\n\
ChatGPT:`,
temperature: 0,
max_tokens: 100,
stop: ["human:", "AI:", "Rayyan"],
});
interaction.reply(`${gptResponse.choices[0].text}`);
return;
} catch (err) {
console.log(err);
}
},
};
当我在discord中执行斜线命令时,我期望discord机器人对我的问题给出正确的答案
1条答案
按热度按时间mrwjdhj31#
问题
您使用Python函数(即
openai.Completion.create
)而不是NodeJS函数(即openai.createCompletion
)来获得完成。解决方案
把这个换了。。
...这个
另外,将参数
engine
更改为model
,如下所示:参见documentation。
请accept我的答案,如果这解决了你的问题。:)