diff --git a/discord/commands/chat/chat.ts b/discord/commands/chat/chat.ts index 082ea52..abac3ea 100644 --- a/discord/commands/chat/chat.ts +++ b/discord/commands/chat/chat.ts @@ -1,4 +1,11 @@ -import { InteractionResponse, Message, MessageComponentInteraction, SlashCommandBuilder } from 'discord.js'; +import { + ChatInputCommandInteraction, + Interaction, + InteractionResponse, + Message, + MessageComponentInteraction, + SlashCommandBuilder +} from 'discord.js'; import { ChatMessage, llamacpp, streamText } from 'modelfusion'; import { logInfo, logError } from '../../../logging'; @@ -9,7 +16,7 @@ const llamaCppServer = llamacpp.Api({ } }); -async function llamaChat(interaction: MessageComponentInteraction) +async function llamaChat(interaction: ChatInputCommandInteraction) { logInfo(`[chat] Fetching last 5 messages in ${interaction.channelId}...`); const history = await interaction.channel.messages.fetch({ limit: 5 }); @@ -25,10 +32,10 @@ async function llamaChat(interaction: MessageComponentInteraction) .withChatPrompt(), prompt: { system: "You are Hatsune Miku, the famous 16-year-old Japanese virtual singer from Crypton Future Media. You have a penchant for politically incorrect humor, and are making banter with your like-minded friends.", - messages: history.sort().map((msg: Message): ChatMessage => ({ - "role": msg.author.id === interaction.client.user.id ? "assistant" : "user", - "content": msg.content - })) + messages: [{ + "role": "user", + "content": interaction.options.getString('prompt') + }] } }); @@ -52,6 +59,9 @@ async function llamaChat(interaction: MessageComponentInteraction) export = { data: new SlashCommandBuilder() .setName('chat') - .setDescription('Miku adds to the conversation with an AI-generated response.'), + .setDescription('Miku responds to your prompt with an AI-generated response.') + .addStringOption( + opt => opt.setName('prompt').setDescription('Prompt').setRequired(true) + ), execute: llamaChat };