mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-17 18:37:07 -04:00
improve gemini-pro command
This commit is contained in:
parent
ab2ddea506
commit
475d83987d
4 changed files with 41 additions and 13 deletions
|
@ -1,24 +1,29 @@
|
||||||
|
const { googleGenaiGeminiApi } = require("#api");
|
||||||
const { PERMISSION_GROUPS } = require("#constants");
|
const { PERMISSION_GROUPS } = require("#constants");
|
||||||
const { LlmModelsGenerate } = require("#obelisk");
|
|
||||||
|
|
||||||
const { createEmbed } = require("#utils/embed");
|
const { createEmbed } = require("#utils/embed");
|
||||||
const { acknowledge } = require("#utils/interactions");
|
const { acknowledge } = require("#utils/interactions");
|
||||||
const { stringwrap, iconPill, smallIconPill } = require("#utils/markdown");
|
const { stringwrap, iconPill, smallIconPill } = require("#utils/markdown");
|
||||||
const { editOrReply } = require("#utils/message");
|
const { editOrReply } = require("#utils/message");
|
||||||
const { STATIC_ICONS } = require("#utils/statics");
|
const { STATIC_ICONS, STATICS, STATIC_ASSETS } = require("#utils/statics");
|
||||||
const { hasFeature } = require("#utils/testing");
|
const { hasFeature } = require("#utils/testing");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'gemini-pro',
|
name: 'gemini-pro',
|
||||||
label: 'text',
|
label: 'text',
|
||||||
aliases: ['gpro'],
|
aliases: ['gpro','gempro','gem-pro'],
|
||||||
metadata: {
|
metadata: {
|
||||||
description: `${iconPill("generative_ai", "LIMITED TESTING")}\n${smallIconPill("reply", "Supports Replies")}\n\nRun Gemini 1.0 Pro with a custom prompt.`,
|
description: `${iconPill("generative_ai", "LIMITED TESTING")}\n${smallIconPill("reply", "Supports Replies")}\n\nRun Gemini 2.5 Pro with a custom prompt.`,
|
||||||
description_short: 'Gemini-1.0-Pro',
|
description_short: 'Gemini 2.5 Pro',
|
||||||
examples: ['gem why do they call it oven when you of in the cold food of out hot eat the food'],
|
examples: ['gem why do they call it oven when you of in the cold food of out hot eat the food'],
|
||||||
category: 'limited',
|
category: 'limited',
|
||||||
usage: 'gemini-pro <prompt>'
|
usage: 'gemini-pro <input> [<prompt>]'
|
||||||
},
|
},
|
||||||
|
args: [
|
||||||
|
{ name: 'prompt', default: '', required: false, help: "The starting system prompt." },
|
||||||
|
{ name: 'model', default: 'gemini-2.5-pro-preview-05-06', required: false, help: "The model." },
|
||||||
|
// { name: 'temperature', default: 0.25, required: false, help: "Model temperature." },
|
||||||
|
],
|
||||||
permissionsClient: [...PERMISSION_GROUPS.baseline, ...PERMISSION_GROUPS.attachments],
|
permissionsClient: [...PERMISSION_GROUPS.baseline, ...PERMISSION_GROUPS.attachments],
|
||||||
run: async (context, args) => {
|
run: async (context, args) => {
|
||||||
if(!await hasFeature(context, "ai/gemini/text")) return;
|
if(!await hasFeature(context, "ai/gemini/text")) return;
|
||||||
|
@ -26,19 +31,33 @@ module.exports = {
|
||||||
|
|
||||||
if(!args.text) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (text).`))
|
if(!args.text) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (text).`))
|
||||||
|
|
||||||
|
let model = "gemini-2.5-pro-preview-05-06"
|
||||||
|
if(args.model && await hasFeature(context, "ai/gpt/model-selection")) model = args.model;
|
||||||
|
|
||||||
let input = args.text;
|
let input = args.text;
|
||||||
|
|
||||||
try{
|
let prompt = `You are a friendly assistant 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.\n- When answering a question, be concise and to the point.\n- Try to keep responses below 1000 characters. This does not apply to subjects that require more exhaustive or in-depth explanation.\n- Respond in a natural way, using Markdown formatting.`
|
||||||
await editOrReply(context, createEmbed("ai_custom", context, STATIC_ICONS.ai_gemini))
|
if(args.prompt !== "") prompt = args.prompt
|
||||||
|
|
||||||
let res = await LlmModelsGenerate(context, "gemini-1.5-pro", input, "BLOCK_NONE")
|
try{
|
||||||
|
await editOrReply(context, createEmbed("defaultNoFooter", context, {
|
||||||
|
author: {
|
||||||
|
iconUrl: STATIC_ICONS.ai_gemini,
|
||||||
|
name: ``
|
||||||
|
},
|
||||||
|
image: {
|
||||||
|
url: STATIC_ASSETS.chat_loading_small
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
|
let res = await googleGenaiGeminiApi(context, model, input, prompt)
|
||||||
|
|
||||||
let description = []
|
let description = []
|
||||||
let files = [];
|
let files = [];
|
||||||
|
|
||||||
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.candidates[0]?.output
|
let output = res.response.body.output
|
||||||
if(!output) return editOrReply(context, createEmbed("error", context, `Gemini 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)
|
||||||
|
@ -57,7 +76,7 @@ module.exports = {
|
||||||
},
|
},
|
||||||
description: description.join('\n'),
|
description: description.join('\n'),
|
||||||
footer: {
|
footer: {
|
||||||
text: `Generative AI is experimental • Data submitted to Gemini may be used by Google for training.`
|
text: `${model} • Data submitted to Gemini may be used by Google for training.`
|
||||||
}
|
}
|
||||||
})],
|
})],
|
||||||
files
|
files
|
||||||
|
@ -65,7 +84,7 @@ module.exports = {
|
||||||
} catch(e){
|
} catch(e){
|
||||||
console.log(e)
|
console.log(e)
|
||||||
if(e.response?.body?.message) return editOrReply(context, createEmbed("error", context, e.response.body.message))
|
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.`))
|
return editOrReply(context, createEmbed("error", context, `Gemini API failed.`))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
|
@ -8,6 +8,7 @@ const Api = Object.freeze({
|
||||||
HOST: Hosts.prod,
|
HOST: Hosts.prod,
|
||||||
|
|
||||||
GOOGLE_GENERATIVEAI_EDIT_IMAGE: '/google/generativeai/edit-image',
|
GOOGLE_GENERATIVEAI_EDIT_IMAGE: '/google/generativeai/edit-image',
|
||||||
|
GOOGLE_GENERATIVEAI_GEMINI_API: '/google/generativeai/gemini',
|
||||||
GOOGLE_GENERATIVEAI_IMAGEN: '/google/generativeai/imagen',
|
GOOGLE_GENERATIVEAI_IMAGEN: '/google/generativeai/imagen',
|
||||||
GOOGLE_PERSPECTIVE: '/google/perspective/analyze',
|
GOOGLE_PERSPECTIVE: '/google/perspective/analyze',
|
||||||
GOOGLE_SPEECH_RECOGNIZE: '/google/speech/recognize',
|
GOOGLE_SPEECH_RECOGNIZE: '/google/speech/recognize',
|
||||||
|
|
|
@ -49,6 +49,14 @@ module.exports.googleGenaiEditImage = async function(context, prompt, url){
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports.googleGenaiGeminiApi = async function(context, model, input, prompt){
|
||||||
|
return await request(Api.GOOGLE_GENERATIVEAI_GEMINI_API, "GET", {}, {
|
||||||
|
prompt,
|
||||||
|
input,
|
||||||
|
model
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
module.exports.googleGenaiImagen = async function(context, prompt, imageCount = 2){
|
module.exports.googleGenaiImagen = async function(context, prompt, imageCount = 2){
|
||||||
return await request(Api.GOOGLE_GENERATIVEAI_IMAGEN, "GET", {}, {
|
return await request(Api.GOOGLE_GENERATIVEAI_IMAGEN, "GET", {}, {
|
||||||
prompt: prompt,
|
prompt: prompt,
|
||||||
|
|
|
@ -215,7 +215,7 @@ const Statics = Object.freeze({
|
||||||
revision: 0
|
revision: 0
|
||||||
},
|
},
|
||||||
ai_gemini: {
|
ai_gemini: {
|
||||||
file: "icons/aiv2/gemini_spark.png",
|
file: "icons/aiv2/gemini_spark_v2.png",
|
||||||
revision: 0
|
revision: 0
|
||||||
},
|
},
|
||||||
ai_palm_idle: {
|
ai_palm_idle: {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue