#Max Tokens issue

1 messages · Page 1 of 1 (latest)

lost swan
#

Sending a create completion request via openai, that is then handled by a discord bot to send the message to a channel.

The returned completion is typically cut off somewhere around 1 sentence.

I tried to specify with maxTokens, but it generated a very very long error.

Here is the relevant code:

    console.log("Bot is ready to send messages!");

    // Send a message every 60 seconds
    setInterval(async () => {
        try {
            // Use the OpenAI API to generate a message
            const completion = await openai.createCompletion({
                model: "text-davinci-003",
                prompt: "give me a short sentence with no context",
                maxTokens: 1000
              });
            const message = completion.data.choices[0].text;
            console.log("Sending message:", message);

            // Send the message to the designated channel
            const channel = client.channels.cache.get("channel id");
            channel.send(message);
        } catch (err) {
            console.error("Error sending message:", err);
        }
    }, 10000);
});```