This commit is contained in:
derpystuff 2023-11-05 20:40:02 +01:00
parent 6e1a5f1cdb
commit 5da051b3b1
8 changed files with 10 additions and 5 deletions

View file

@ -14,11 +14,12 @@ module.exports = {
description: 'Ask AI questions. May not be accurate.',
description_short: 'AI questions',
examples: ['ask How many otter species are there?'],
category: 'hidden',
category: 'broken',
usage: 'ask <prompt>'
},
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY],
run: async (context, args) => {
return;
context.triggerTyping();
if (!args.text) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (text).`))
try {

View file

@ -1,79 +0,0 @@
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");
module.exports = {
name: 'bard',
label: 'text',
metadata: {
description: `${iconPill("generative_ai", "LIMITED TESTING")}\n\nChat with <:bard:1163200801871765504> Bard.`,
description_short: 'Chat with Bard.',
examples: ['bard How many otter species are there?'],
category: 'limited',
usage: 'bard <input>'
},
args: [],
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;
let inputDisplay = args.text.replace(/\n/g, ' ')
if(inputDisplay.length >= 50) inputDisplay = inputDisplay.substr(0,50) + '...'
try{
await editOrReply(context, createEmbed("ai_custom", context, STATIC_ICONS.ai_bard))
let res = await superagent.post(`${process.env.AI_SERVER}/google/bard`)
.set({
Authorization: process.env.AI_SERVER_KEY
})
.send({
input
})
let description = []
let files = [];
if(!res.body.output) return editOrReply(context, createEmbed("error", context, `Bard returned an error. Try again later.`))
if(res.body.output.length <= 4000) description.push(res.body.output)
else {
files.push({
filename: `chat.${Date.now().toString(36)}.txt`,
value: Buffer.from(res.body.output)
})
}
return editOrReply(context, {
embeds:[createEmbed("defaultNoFooter", context, {
author: {
name: inputDisplay,
iconUrl: STATIC_ICONS.ai_bard_idle
},
description: description.join('\n'),
footer: {
text: `Bard • This information may be inaccurate or biased`
}
})],
files
})
}catch(e){
if(e.response.body?.message) return editOrReply(context, createEmbed("warning", context, e.response.body.message))
console.log(e)
return editOrReply(context, createEmbed("error", context, `Unable to generate text.`))
}
}
};

View file

@ -1,119 +0,0 @@
const { createEmbed } = require('../../../labscore/utils/embed')
const { editOrReply } = require('../../../labscore/utils/message')
const { canUseLimitedTestCommands, isLimitedTestUser } = require('../../../labscore/utils/testing')
const { STATICS } = require('../../../labscore/utils/statics');
const superagent = require('superagent')
const { iconPill } = require('../../../labscore/utils/markdown')
const { Permissions } = require("detritus-client/lib/constants");
const MODELS = {
"CHATGPT": {
icon: STATICS.chatgpt,
name: "ChatGPT"
},
"GPT4": {
icon: STATICS.openai,
name: "GPT-4"
}
}
module.exports = {
name: 'chat',
label: 'text',
aliases: ['openai','gpt','chatgpt'],
metadata: {
description: `${iconPill("generative_ai", "LIMITED TESTING")}\n\nTalk to ChatGPT.`,
description_short: 'Talk to ChatGPT.',
examples: ['chat How many otter species are there?'],
category: 'limited',
usage: 'chat <input> [-prompt <prompt override>]'
},
args: [
{ name: 'prompt', default: '', required: false, help: "The starting system prompt." },
{ name: 'temperature', default: 0.5, required: false, help: "Model temperature." },
{ name: 'model', default: 'CHATGPT', required: false, help: "The model to use. (Model cannot be changed for regular users)" },
],
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;
let prompt = `You are a friendly chat bot designed to help people.\n- Today\'s date is ${new Date().toLocaleDateString('en-us', { weekday:"long", year:"numeric", month:"long", day:"numeric"})}\n- You should always use gender neutral pronouns when possible.`
if(args.prompt !== "") prompt = args.prompt
// Get content if the user replies to anything
if(context.message.messageReference) {
let msg = await context.message.channel.fetchMessage(context.message.messageReference.messageId);
if(msg.content && msg.content.length) input = msg.content
else if(msg.embeds?.length) for(const e of msg.embeds) if(e[1].description?.length) { input = e[1].description; break; }
prompt = args.text
if(args.prompt !== "") return editOrReply(context, createEmbed("warning", context, `Prompt parameter is unsupported for message replies.`))
}
let model = "CHATGPT"
if(args.model && isLimitedTestUser(context.user)) model = args.model
if(!MODELS[model]) return editOrReply(context, createEmbed("warning", context, `Invalid or unsupported model (${model}).`))
let temperature = "0.25"
if(args.temperature !== 0.25) temperature = parseFloat(args.temperature)
try{
await editOrReply(context, createEmbed("ai", context, "Generating response..."))
let res = await superagent.post(`${process.env.AI_SERVER}/openai`)
.set({
Authorization: process.env.AI_SERVER_KEY
})
.send({
prompt,
input: [input],
temperature,
model
})
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: `chat.${Date.now().toString(36)}.txt`,
value: Buffer.from(res.body.output)
})
}
return editOrReply(context, {
embeds:[createEmbed("defaultNoFooter", context, {
author: {
iconUrl: MODELS[model].icon,
name: inputDisplay
},
description: description.join('\n'),
footer: {
text: `${MODELS[model].name} • This information may be inaccurate or biased`
}
})],
files
})
}catch(e){
console.log(e)
return editOrReply(context, createEmbed("error", context, `Unable to generate text.`))
}
}
};

View file

@ -1,79 +0,0 @@
const { createEmbed } = require('../../../labscore/utils/embed')
const { editOrReply } = require('../../../labscore/utils/message')
const { canUseLimitedTestCommands } = require('../../../labscore/utils/testing')
const { STATICS } = require('../../../labscore/utils/statics');
const superagent = require('superagent')
const { iconPill, smallIconPill } = require('../../../labscore/utils/markdown')
const { Permissions } = require("detritus-client/lib/constants");
module.exports = {
name: 'dalle',
label: 'text',
metadata: {
description: `${iconPill("generative_ai", "LIMITED TESTING")}\n\nGenerate images with DALL-E`,
description_short: 'Generate images with DALL-E.',
examples: ['dalle Otter, in the style of the great wave'],
category: 'limited',
usage: 'dalle <prompt>'
},
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 prompt = 'You are a friendly chat bot designed to help people. You should always use gender neutral pronouns when possible.'
if(args.prompt !== "") prompt = args.prompt
try{
await editOrReply(context, createEmbed("ai", context, "Generating image..."))
let res = await superagent.post(`${process.env.AI_SERVER}/openai/dalle`)
.set({
Authorization: process.env.AI_SERVER_KEY
})
.send({
prompt: args.text,
model: "DALLE2"
})
// Fetch the image
let img = await superagent.get(res.body.output)
let inputDisplay = args.text
if(inputDisplay.length >= 50) inputDisplay = inputDisplay.substr(0,50) + '...'
let description = [smallIconPill("generative_ai", inputDisplay), '']
let files = [];
if(!res.body.output) res.body.output = '[Empty Response]'
const f = `lcdalle.${Date.now().toString(36)}.png`;
files.push({
filename: f,
value: img.body
})
return editOrReply(context, {
embeds:[createEmbed("default", context, {
description: description.join('\n'),
image: {
url: "attachment://" + f
},
footer: {
text: `OpenAI DALL-E • ${context.application.name}`,
iconUrl: STATICS.openai
}
})],
files
})
}catch(e){
console.log(e)
return editOrReply(context, createEmbed("error", context, `Unable to generate text.`))
}
}
};