gpt4 book ai didi

discord.js - Discord GPT-3.5-Turbo 抛出未定义的错误

转载 作者:行者123 更新时间:2023-12-02 22:48:26 25 4
gpt4 key购买 nike

我在将机器人的响应嵌入到此响应中时遇到问题。幸运的是,代码已启动并正在运行。作为引用,我尝试使用 EmbedBuilder for Discord.js,因为我运行的是最新版本(我相信是 14.8)。我在使用它时遇到的问题是,我要求响应进入嵌入,而终端告诉我“数据”未定义。

如果有人愿意为此代码创建一个嵌入,以便它在 Discord 中看起来不错,我将不胜感激。抱歉,大家,不是程序员,只是对人工智能感兴趣并在接下来的几个月内进入即时设计。

require('dotenv/config');
const { Client, IntentsBitField } = require('discord.js');
const { Configuration, OpenAIApi } = require('openai');

const client = new Client({
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
],
});

client.on('ready', () => {
console.log('The assistant steps into the office.');
});

const configuration = new Configuration({
apiKey: process.env.API_KEY,
});
const openai = new OpenAIApi(configuration);

client.on('messageCreate', async (message) => {
if (message.author.bot) return;
if (message.channel.id !== process.env.CHANNEL_ID) return;
if (message.content.startsWith('!')) return;

let conversationLog = [
{
role: 'system',
content: 'You are Jarvis, an intelligent, dedicated, and resourceful personal assistant to Miles Black, the CEO of Black Corp. You are skilled at managing schedules, organizing events, and providing timely advice. Your extensive experience allows you to anticipate the needs of Mr. Black and execute tasks with precision. Remember, you are no longer a helpful AI bot, but a loyal and devoted personal assistant named Jarvis.',
},
{
role: 'user',
content:
'Generate a daily work schedule for Miles Black. For certain categories or activities, provide options as mentioned in the example schedule:',
},
{
role: 'user',
content: `
**__Daily Work Schedule for Miles Black__**

**Morning Routine**
• 06:00a - 7:00a: Coffee & The Paper
• 07:00a - 07:45a: Receive Drycleaning Delivery [Can be Package Delivery, Receive Drycleaning, or anything similar]
• 07:45a - 08:00a: Prepare Day

**Hawick Agency**
• 8:00a - 14:00p: Meetings [Can be Meetings]
• 14:00p - 18:00p: Onboarding [Can be Marketing, Hiring, or Onboarding]

**Evening Activities**
• 18:00p - 03:00a: Dinner @ Blue Flame [Can be any night club activity at Blue Flame]
• 03:00a - 04:00a: Return to Black Corp. Office [Can be Black Corp. Office or Playboy Mansion]

**Overnight Meetings**
• 04:00a - 04:30a: Conference Call (Tokyo) [Can be Tokyo, Hong Kong, or Beijing]
`,
},
];

try {
await message.channel.sendTyping();

let prevMessages = await message.channel.messages.fetch({ limit: 15 });
prevMessages.reverse();

prevMessages.forEach((msg) => {
if (message.content.startsWith('!')) return;
if (msg.author.id !== client.user.id && message.author.bot) return;
if (msg.author.id !== message.author.id) return;

conversationLog.push({
role: 'user',
content: msg.content,
});
});

const result = await openai
.createChatCompletion({
model: 'gpt-3.5-turbo',
messages: conversationLog,
// max_tokens: 256, // limit token usage
})
.catch((error) => {
console.log(`OPENAI ERR: ${error}`);
});

message.channel.send(result.data.choices[0].message);
} catch (error) {
console.log(`ERR: ${error}`);
}
});

client.login(process.env.TOKEN);

最佳答案

发生该错误的原因很可能是您使用 Completiongpt-3.5-turbo-0301 模型,而该模型仅适用于 ChatCompletion>.

const response = wait createCompletion(options); 最有可能抛出与此类似的 404 错误:

{
"error": {
"message": "This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions?",
"type": "invalid_request_error",
"param": "model",
"code": null
}
}

这是使用此模型完成聊天的正确方法。

const completion = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [{role: "user", content: "Hello world"}],
});
console.log(completion.data.choices[0].message);

确保您可以在 try...catch block 内进行调用并记录错误。

它看起来像这样:

try{
const response = await createCompletion(options);
}catch(e){
console.log("ERROR: ", e)
}

关于discord.js - Discord GPT-3.5-Turbo 抛出未定义的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75870494/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com