#Status Code 400 with JS and Davinci Model

8 messages · Page 1 of 1 (latest)

thorn trail
#

I have been trying this many times over with no success. Basically, just a simple discord bot that retrieves messages and uses them as context as well as user message as prompt. This code framework works great with gpt3.5-turbo. But I have altered it to try and use the Davinci model, with no luck. At one point it was recommended to me to add the prompt line for join.

I am idk, noobish, at javascript and OpenAI API, this is my fifth bot.

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 bot is online!');
});
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.author.bot || !message.mentions.has(client.user.id)) return;
    if (!message.mentions.has(client.user) && !message.reference?.messageId === client.user.id) return;
    let conversationLog = [{ role: 'system', content: 'You are a friendly chatbot.' }];
    try {
      await message.channel.sendTyping();
      let prevMessages = await message.channel.messages.fetch({ limit: 5 });
      prevMessages.reverse();
      prevMessages.forEach((msg) => {    
        conversationLog.push({
          role: 'user',
          content: msg.content,
        });
      });
      const prompt = conversationLog.map(({ content }) => content).join('\n');
      const result = await openai.createChatCompletion({
        prompt: prompt,
        model: "davinci",
        max_tokens: 2500,
        temperature: 0.3,
        top_p: 0.3,
        presence_penalty: 0,
        frequency_penalty: 0.5,
        context: conversationLog,
      })
      const generatedText = result.data.choices[0].text;
      return message.reply(generatedText);
    } catch (error) {
      console.log(`ERR: ${error}`);
    }
  });
client.login(process.env.TOKEN);
pliant steppe
valid canopy
#

You're calling the wrong model and endpoint. If you want to use DaVinci you need to add it as:
"model": "text-davinci-003" and it'll be createCompletion

thorn trail
#

Ty im going to look into this

pliant steppe
#

But he still has the wrong endpoint.

valid canopy
# pliant steppe This is not true. It's just davinci now.

I've been using text-davinci-003 for months and is working perfectly fine.

Maybe they've added support to the new term but any of the examples you can pull up & it's the 003 model. So I'm guessing it's not the model name but the endpoint that's causing the error.