OpenAI changes
This commit is contained in:
parent
02ec0de4d4
commit
6f0e802680
1 changed files with 5 additions and 6 deletions
|
@ -1,12 +1,11 @@
|
||||||
import { ApplyOptions } from '@sapphire/decorators';
|
import { ApplyOptions } from '@sapphire/decorators';
|
||||||
import { Args, Command } from '@sapphire/framework';
|
import { Args, Command } from '@sapphire/framework';
|
||||||
import { AttachmentBuilder, Message, blockQuote, codeBlock } from 'discord.js';
|
import { AttachmentBuilder, Message, blockQuote, codeBlock } from 'discord.js';
|
||||||
import { Configuration, OpenAIApi } from 'openai';
|
import OpenAI from 'openai';
|
||||||
|
|
||||||
const configuration = new Configuration({
|
const openai = new OpenAI({
|
||||||
apiKey: process.env.OPENAI_API_KEY
|
apiKey: process.env.OPENAI_API_KEY
|
||||||
});
|
});
|
||||||
const openai = new OpenAIApi(configuration);
|
|
||||||
|
|
||||||
@ApplyOptions<Command.Options>({
|
@ApplyOptions<Command.Options>({
|
||||||
description: 'You can ACTUALLY ask Himbot something! So cool!',
|
description: 'You can ACTUALLY ask Himbot something! So cool!',
|
||||||
|
@ -41,7 +40,7 @@ export class UserCommand extends Command {
|
||||||
? await interactionOrMessage.channel.send({ content: '🤔 Thinking... 🤔' })
|
? await interactionOrMessage.channel.send({ content: '🤔 Thinking... 🤔' })
|
||||||
: await interactionOrMessage.reply({ content: '🤔 Thinking... 🤔', fetchReply: true });
|
: await interactionOrMessage.reply({ content: '🤔 Thinking... 🤔', fetchReply: true });
|
||||||
|
|
||||||
const chatCompletion = await openai.createChatCompletion({
|
const chatCompletion = await openai.chat.completions.create({
|
||||||
model: 'gpt-4',
|
model: 'gpt-4',
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
|
@ -51,13 +50,13 @@ export class UserCommand extends Command {
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
const content = blockQuote(`> ${prompt}\n${codeBlock(`${chatCompletion.data.choices[0].message?.content}`)}`);
|
const content = blockQuote(`> ${prompt}\n${codeBlock(`${chatCompletion.choices[0].message?.content}`)}`);
|
||||||
|
|
||||||
const messageAttachment: AttachmentBuilder[] = [];
|
const messageAttachment: AttachmentBuilder[] = [];
|
||||||
|
|
||||||
if (content.length > 2000) {
|
if (content.length > 2000) {
|
||||||
messageAttachment.push(
|
messageAttachment.push(
|
||||||
new AttachmentBuilder(Buffer.from(`> ${prompt}\n${`${chatCompletion.data.choices[0].message?.content}`}`, 'utf-8'), {
|
new AttachmentBuilder(Buffer.from(`> ${prompt}\n${`${chatCompletion.choices[0].message?.content}`}`, 'utf-8'), {
|
||||||
name: 'response.txt',
|
name: 'response.txt',
|
||||||
description: "Himbot's Response"
|
description: "Himbot's Response"
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue