V3
This commit is contained in:
parent
9341181f99
commit
236ca371bb
39 changed files with 659 additions and 1531 deletions
10
src/commands/default/ping.ts
Normal file
10
src/commands/default/ping.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
import { SlashCommandBuilder, CommandInteraction } from "discord.js";
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("ping")
|
||||
.setDescription("Replies with Pong!"),
|
||||
async execute(interaction: CommandInteraction) {
|
||||
await interaction.reply("Pong!");
|
||||
},
|
||||
};
|
57
src/commands/singleRequests/ask.ts
Normal file
57
src/commands/singleRequests/ask.ts
Normal file
|
@ -0,0 +1,57 @@
|
|||
import { SlashCommandBuilder, ChatInputCommandInteraction } from "discord.js";
|
||||
import { getChatResponse, MistralMessage, Models, InputPrice, OutputPrice, ReturnedValue } from "../../libs/mistralai";
|
||||
import { User, connectToDb, addUser, getUser, incrementQuota } from "../../libs/mysql";
|
||||
|
||||
const data = require("../../../config.json");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("ask")
|
||||
.setDescription("Make a single request to mistral API")
|
||||
.setDMPermission(false)
|
||||
.addStringOption(option =>
|
||||
option.setName("prompt").setDescription("The prompt to send to the API").setRequired(true)
|
||||
),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
if (interaction.member?.user.id != '372437660167438337') {
|
||||
return interaction.reply("you are not allowed to use this command");
|
||||
}
|
||||
|
||||
await interaction.deferReply();
|
||||
|
||||
const connection = await connectToDb();
|
||||
|
||||
var user: User[] = await getUser(connection, interaction.member?.user.id);
|
||||
|
||||
if (!user[0]) {
|
||||
await addUser(connection, interaction.member?.user.username, interaction.member?.user.id);
|
||||
user = await getUser(connection, interaction.member?.user.id);
|
||||
}
|
||||
|
||||
if (user[0].quota > 0.4) {
|
||||
interaction.editReply("You have exceed your quota.")
|
||||
connection.end();
|
||||
return;
|
||||
}
|
||||
|
||||
const prompt: string | null = interaction.options.getString("prompt");
|
||||
|
||||
const messages: MistralMessage[] = [
|
||||
{
|
||||
role: "system",
|
||||
content: data.defaultPrompt
|
||||
},
|
||||
{
|
||||
role: "user",
|
||||
content: prompt ? prompt : ""
|
||||
},
|
||||
]
|
||||
|
||||
const response: ReturnedValue = await getChatResponse(messages, Models.multi_tiny);
|
||||
|
||||
await incrementQuota(connection, interaction.member?.user.id, InputPrice.multi_tiny * response.promptUsage + OutputPrice.multi_tiny * response.responseUsage);
|
||||
connection.end();
|
||||
|
||||
interaction.editReply(response.message);
|
||||
},
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue