mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-09 22:53:06 -04:00
gemini text
This commit is contained in:
parent
9b6ef0da26
commit
3b478bd69e
4 changed files with 79 additions and 1 deletions
|
@ -46,7 +46,7 @@ module.exports = {
|
||||||
if(res.response.body.message) return editOrReply(context, createEmbed("error", context, e.response.body.message))
|
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
|
let output = res.response.body.gemini?.candidates[0]?.content?.parts[0]?.text
|
||||||
if(!output) return editOrReply(context, createEmbed("error", context, `PaLM 2 returned an error. Try again later.`))
|
if(!output) return editOrReply(context, createEmbed("error", context, `Gemini returned an error. Try again later.`))
|
||||||
|
|
||||||
|
|
||||||
if(output.length <= 4000) description.push(output)
|
if(output.length <= 4000) description.push(output)
|
||||||
|
|
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.`))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
|
@ -7,6 +7,7 @@ const ObeliskApi = Object.freeze({
|
||||||
HOST: ObeliskHosts.prod,
|
HOST: ObeliskHosts.prod,
|
||||||
|
|
||||||
GOOGLE_BARD: "/parrot/v1/google:bard",
|
GOOGLE_BARD: "/parrot/v1/google:bard",
|
||||||
|
GEMINI_PRO: "/parrot/v1/google:gemini",
|
||||||
GEMINI_PRO_VISION: "/parrot/v1/google:geminiVision",
|
GEMINI_PRO_VISION: "/parrot/v1/google:geminiVision",
|
||||||
|
|
||||||
SUMMARIZE_WEBPAGES: "/flamingo/v1/web:summarize"
|
SUMMARIZE_WEBPAGES: "/flamingo/v1/web:summarize"
|
||||||
|
|
|
@ -47,6 +47,12 @@ module.exports.bard = async function(context, input){
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports.gemini = async function(context, prompt){
|
||||||
|
return await request(ObeliskApi.GEMINI_PRO, "POST", {}, {
|
||||||
|
prompt
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
module.exports.geminiVision = async function(context, input, url){
|
module.exports.geminiVision = async function(context, input, url){
|
||||||
return await request(ObeliskApi.GEMINI_PRO_VISION, "POST", {}, {
|
return await request(ObeliskApi.GEMINI_PRO_VISION, "POST", {}, {
|
||||||
input,
|
input,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue