mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-09 14:43:05 -04:00
gemini text
This commit is contained in:
parent
9b6ef0da26
commit
3b478bd69e
4 changed files with 79 additions and 1 deletions
71
commands/message/genai/gemini.js
Normal file
71
commands/message/genai/gemini.js
Normal file
|
@ -0,0 +1,71 @@
|
|||
const { gemini } = require("../../../labscore/api/obelisk");
|
||||
const { createEmbed } = require("../../../labscore/utils/embed");
|
||||
const { editOrReply } = require("../../../labscore/utils/message");
|
||||
|
||||
const { Permissions } = require("detritus-client/lib/constants");
|
||||
|
||||
const { STATIC_ICONS } = require("../../../labscore/utils/statics");
|
||||
const { stringwrap } = require("../../../labscore/utils/markdown");
|
||||
const { canUseLimitedTestCommands } = require("../../../labscore/utils/testing");
|
||||
module.exports = {
|
||||
name: 'gemini',
|
||||
label: 'text',
|
||||
aliases: ['gem'],
|
||||
metadata: {
|
||||
description: 'Run Gemini Pro with a custom prompt.',
|
||||
description_short: 'Gemini',
|
||||
examples: ['gem why do they call it oven when you of in the cold food of out hot eat the food'],
|
||||
category: 'limited',
|
||||
usage: 'gemini <prompt>'
|
||||
},
|
||||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.ATTACH_FILES, Permissions.READ_MESSAGE_HISTORY],
|
||||
run: async (context, args) => {
|
||||
context.triggerTyping();
|
||||
if(!canUseLimitedTestCommands(context)) return;
|
||||
context.triggerTyping();
|
||||
|
||||
if(!args.text) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (text).`))
|
||||
|
||||
let input = args.text;
|
||||
|
||||
try{
|
||||
await editOrReply(context, createEmbed("ai_custom", context, STATIC_ICONS.ai_gemini))
|
||||
|
||||
let res = await gemini(context, input)
|
||||
|
||||
let description = []
|
||||
let files = [];
|
||||
|
||||
if(res.response.body.message) return editOrReply(context, createEmbed("error", context, e.response.body.message))
|
||||
|
||||
let output = res.response.body.gemini?.candidates[0]?.content?.parts[0]?.text
|
||||
if(!output) return editOrReply(context, createEmbed("error", context, `Gemini returned an error. Try again later.`))
|
||||
|
||||
if(output.length <= 4000) description.push(output)
|
||||
else {
|
||||
files.push({
|
||||
filename: `gemini.${Date.now().toString(36)}.txt`,
|
||||
value: Buffer.from(output)
|
||||
})
|
||||
}
|
||||
|
||||
return editOrReply(context, {
|
||||
embeds:[createEmbed("defaultNoFooter", context, {
|
||||
author: {
|
||||
name: stringwrap(input, 50, false),
|
||||
iconUrl: STATIC_ICONS.ai_gemini
|
||||
},
|
||||
description: description.join('\n'),
|
||||
footer: {
|
||||
text: `Generative AI is experimental • Data submitted to Gemini may be used by Google for training.`
|
||||
}
|
||||
})],
|
||||
files
|
||||
})
|
||||
} catch(e){
|
||||
console.log(e)
|
||||
if(e.response?.body?.message) return editOrReply(context, createEmbed("error", context, e.response.body.message))
|
||||
return editOrReply(context, createEmbed("error", context, `Unable to generate response.`))
|
||||
}
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue