add clyde

This commit is contained in:
derpystuff 2023-11-16 21:45:21 +01:00
parent 969d526734
commit 1a69741b36
2 changed files with 129 additions and 0 deletions

View file

@ -0,0 +1,119 @@
const { createEmbed } = require('../../../labscore/utils/embed')
const { editOrReply } = require('../../../labscore/utils/message')
const { canUseLimitedTestCommands } = require('../../../labscore/utils/testing')
const { STATIC_ICONS } = require('../../../labscore/utils/statics');
const superagent = require('superagent')
const { iconPill } = require('../../../labscore/utils/markdown')
const { Permissions } = require("detritus-client/lib/constants");
const quips = `Crunching the data, one byte at a time...
Loading the knowledge banks, please wait...
Assembling the perfect response, just for you...
Spinning up the chatbot engines...
Brewing up a fresh batch of answers...
Analyzing the question, hold on tight...
Processing your query, please stand by...
Loading the neural network...
Stirring the thoughts, almost there...
Preparing a witty comeback, just a moment...
Fueling the brain with information...
Weaving together words, just for you...
Unleashing the intelligence, stand by...
Stirring the creativity, almost ready...
Syncing with the vast knowledge base...
Igniting the conversational skills...
Compiling a response, just a few more seconds...
Charging up the linguistic prowess...
Loading the arsenal of clever comebacks...
Infusing the responses with wit and charm...`.split('\n')
module.exports = {
name: 'clyde',
label: 'text',
metadata: {
description: `${iconPill("generative_ai", "LIMITED TESTING")}\n\nTalk to Clyde 🪦 .`,
description_short: 'Talk to ChatGPT.',
examples: ['chat How many otter species are there?'],
category: 'limited',
usage: 'chat <input> [-prompt <prompt override>]'
},
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.ATTACH_FILES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY],
run: async (context, args) => {
if(!canUseLimitedTestCommands(context)) return;
context.triggerTyping();
if(!args.text) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (text).`))
let input = args.text;
// You can also reply with a gif, by using @gif("description of the gif you want to send"), for example if you wanted to send a cat gif, you would do: @gif("happy cat"). Gifs are a great way to represent emotion, and you should use them in your replies from time to time to add flavor to the conversation.
const prompt = `You are named Clyde - and are currently chatting in a Discord server.
Do not include name: or message: in your response.
Information about your environment:
- The server you are in is called: ${context.guild.name}
- The server is owned by: ${context.guild.owner.username}
- The channel you are in is called: #${context.channel.name}
You can use this information about the chat participants in the conversation in your replies. Use this information to answer questions, or add flavor to your responses.
${context.user.username}
You only have access to a limited number of text chats in this channel. You cannot access any other information on Discord. You can't see images or avatars. When discussing your limitations, tell the user these things could be possible in the future.
Current time: ${new Date().toLocaleDateString('en-us', { weekday:"long", year:"numeric", month:"long", day:"numeric"})}.`
try{
let e = createEmbed("ai", context, quips[Math.floor(Math.random()*quips.length)])
e.author.iconUrl = STATIC_ICONS.ai_clyde
await editOrReply(context, e)
let res = await superagent.post(`${process.env.AI_SERVER}/openai`)
.set({
Authorization: process.env.AI_SERVER_KEY
})
.send({
prompt,
input: [input],
temperature: "0.75",
model: "CHATGPT"
})
let inputDisplay = args.text.replace(/\n/g, ' ')
if(inputDisplay.length >= 50) inputDisplay = inputDisplay.substr(0,50) + '...'
let description = []
let files = [];
if(!res.body.output) res.body.output = '[Empty Response]'
if(res.body.output.length <= 4000) description.push(res.body.output)
else {
files.push({
filename: `clyde.${Date.now().toString(36)}.txt`,
value: Buffer.from(res.body.output)
})
}
return editOrReply(context, {
embeds:[createEmbed("defaultNoFooter", context, {
author: {
iconUrl: STATIC_ICONS.ai_clyde_idle,
name: inputDisplay
},
description: description.join('\n')
})],
files
})
}catch(e){
console.log(e)
return editOrReply(context, createEmbed("error", context, `Unable to generate text.`))
}
}
};

View file

@ -144,6 +144,14 @@ const Statics = Object.freeze({
file: "icons/core/ico_notice_bard_idle.gif",
revision: 0
},
ai_clyde: {
file: "brands/_clyde/clyde_generating.gif",
revision: 0
},
ai_clyde_idle: {
file: "brands/_clyde/clyde.png",
revision: 0
},
ai_palm_idle: {
file: "icons/core/ico_notice_palm_idle.png",
revision: 0
@ -195,6 +203,8 @@ module.exports.STATIC_ICONS = Object.freeze({
ai: staticAsset(Statics.icons.ai),
ai_bard: staticAsset(Statics.icons.ai_bard),
ai_bard_idle: staticAsset(Statics.icons.ai_bard_idle),
ai_clyde: staticAsset(Statics.icons.ai_clyde),
ai_clyde_idle: staticAsset(Statics.icons.ai_clyde_idle),
ai_palm_idle: staticAsset(Statics.icons.ai_palm_idle),
warning: staticAsset(Statics.icons.warning)
})