From 4aa15da120e0c5665c40c3069339c5497cd5e26c Mon Sep 17 00:00:00 2001 From: derpystuff <3515180-derpystuff@users.noreply.gitlab.com> Date: Wed, 13 Dec 2023 18:44:31 +0100 Subject: [PATCH 01/13] fix bard --- commands/message/limited/bard.js | 19 ++++++------------- labscore/api/obelisk/endpoints.js | 2 ++ labscore/api/obelisk/index.js | 8 ++++++++ 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/commands/message/limited/bard.js b/commands/message/limited/bard.js index 2565277..e41fa78 100644 --- a/commands/message/limited/bard.js +++ b/commands/message/limited/bard.js @@ -9,6 +9,7 @@ const { iconPill, stringwrap } = require('../../../labscore/utils/markdown') const { Permissions, InteractionCallbackTypes } = require("detritus-client/lib/constants"); const { Components } = require('detritus-client/lib/utils'); +const { bard } = require('../../../labscore/api/obelisk'); module.exports = { name: 'bard', @@ -33,27 +34,19 @@ module.exports = { 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 - }) - .query({ - with_drafts: true - }) - .send({ - input - }) + let res = await bard(context, input) + res = res.response let description = [] let files = []; - if(!res.body.output) return editOrReply(context, createEmbed("error", context, `Bard returned an error. Try again later.`)) + if(!res.body.drafts) return editOrReply(context, createEmbed("error", context, `Bard returned an error. Try again later.`)) - if(res.body.output.length <= 4000) description.push(res.body.output) + if(res.body.drafts[0].length <= 4000) description.push(res.body.drafts[0]) else { files.push({ filename: `chat.${Date.now().toString(36)}.txt`, - value: Buffer.from(res.body.output) + value: Buffer.from(res.body.drafts[0]) }) } diff --git a/labscore/api/obelisk/endpoints.js b/labscore/api/obelisk/endpoints.js index 6e4dca1..c0dcf93 100644 --- a/labscore/api/obelisk/endpoints.js +++ b/labscore/api/obelisk/endpoints.js @@ -6,6 +6,8 @@ const ObeliskHosts = Object.freeze({ const ObeliskApi = Object.freeze({ HOST: ObeliskHosts.prod, + GOOGLE_BARD: "/parrot/v1/google:bard", + SUMMARIZE_WEBPAGES: "/flamingo/v1/web:summarize" }) diff --git a/labscore/api/obelisk/index.js b/labscore/api/obelisk/index.js index 6e26084..9e234a2 100644 --- a/labscore/api/obelisk/index.js +++ b/labscore/api/obelisk/index.js @@ -40,6 +40,14 @@ async function request(path, type, headers, args, host) { throw new Error("unsupported, must either use GET or POST"); } +// GENERATIVEAI +module.exports.bard = async function(context, input){ + return await request(ObeliskApi.GOOGLE_BARD, "POST", {}, { + input + }) +} + +// FLAMINGO module.exports.summarizeWebpage = async function(context, url){ return await request(ObeliskApi.SUMMARIZE_WEBPAGES, "POST", {}, { url From 9254eb1abfa58d4d24bfe792351c57c5e5c15811 Mon Sep 17 00:00:00 2001 From: derpystuff <3515180-derpystuff@users.noreply.gitlab.com> Date: Wed, 13 Dec 2023 21:36:18 +0100 Subject: [PATCH 02/13] fix otter --- commands/message/fun/otter.js | 16 ++++++++-------- labscore/api/endpoints.js | 1 + labscore/api/index.js | 6 +++++- labscore/api/obelisk/endpoints.js | 1 + labscore/api/obelisk/index.js | 7 +++++++ 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/commands/message/fun/otter.js b/commands/message/fun/otter.js index 3a3bb14..f7f52d2 100644 --- a/commands/message/fun/otter.js +++ b/commands/message/fun/otter.js @@ -4,6 +4,7 @@ const { editOrReply } = require('../../../labscore/utils/message') const superagent = require('superagent'); const { Permissions } = require("detritus-client/lib/constants"); +const { otter } = require('../../../labscore/api'); module.exports = { name: 'otter', @@ -17,16 +18,15 @@ module.exports = { run: async (context) => { await context.triggerTyping(); try{ - let res = await superagent.get(`https://otter.bruhmomentlol.repl.co/random`) - .set("User-Agent","labscore/2.0") + const ott = (await otter()).response.body - return await editOrReply(context, { - embeds: [ createEmbed("image", context, { - url: `otter.${res.headers["x-file-ext"]}` - })], - files: [{ filename: `otter.${res.headers["x-file-ext"]}`, value: res.body }] - }) + return editOrReply(context, createEmbed("default", context, { + image: { + url: ott.url + } + })) }catch(e){ + console.log(e) return editOrReply(context, createEmbed("error", context, `Unable to fetch otter.`)) } } diff --git a/labscore/api/endpoints.js b/labscore/api/endpoints.js index 5dd9043..53bd8dc 100644 --- a/labscore/api/endpoints.js +++ b/labscore/api/endpoints.js @@ -54,6 +54,7 @@ const Api = Object.freeze({ UTILS_GARFIELD: '/utils/garfield', UTILS_INFERKIT: '/utils/inferkit', UTILS_MAPKIT: '/utils/mapkit', + UTILS_OTTER: '/utils/otter', UTILS_PERSPECTIVE: '/utils/perspective', UTILS_SCREENSHOT: '/utils/screenshot', UTILS_TEXTGENERATOR: '/utils/text-generator', diff --git a/labscore/api/index.js b/labscore/api/index.js index e3c4628..5e9ba04 100644 --- a/labscore/api/index.js +++ b/labscore/api/index.js @@ -304,7 +304,7 @@ module.exports.emojipedia = async function(context, emoji){ }) } -module.exports.garfield = async function(context, emoji){ +module.exports.garfield = async function(context,){ return await request(Api.UTILS_GARFIELD, "GET", {}, {}) } @@ -314,6 +314,10 @@ module.exports.inferkit = async function(context, input){ }) } +module.exports.otter = async function(context){ + return await request(Api.UTILS_OTTER, "GET", {}, {}) +} + module.exports.perspective = async function(context, content = []){ return await request(Api.UTILS_PERSPECTIVE, "GET", {}, { input: content.join('\n\n') diff --git a/labscore/api/obelisk/endpoints.js b/labscore/api/obelisk/endpoints.js index c0dcf93..fb61f0d 100644 --- a/labscore/api/obelisk/endpoints.js +++ b/labscore/api/obelisk/endpoints.js @@ -7,6 +7,7 @@ const ObeliskApi = Object.freeze({ HOST: ObeliskHosts.prod, GOOGLE_BARD: "/parrot/v1/google:bard", + GEMINI_PRO_VISION: "/parrot/v1/google:geminivision", SUMMARIZE_WEBPAGES: "/flamingo/v1/web:summarize" }) diff --git a/labscore/api/obelisk/index.js b/labscore/api/obelisk/index.js index 9e234a2..6d7613b 100644 --- a/labscore/api/obelisk/index.js +++ b/labscore/api/obelisk/index.js @@ -47,6 +47,13 @@ module.exports.bard = async function(context, input){ }) } +module.exports.geminiVision = async function(context, input, url){ + return await request(ObeliskApi.GOOGLE_BARD, "POST", {}, { + input, + url + }) +} + // FLAMINGO module.exports.summarizeWebpage = async function(context, url){ return await request(ObeliskApi.SUMMARIZE_WEBPAGES, "POST", {}, { From ebe629feaebe1327532665b1a48ec0ced5a6cd7a Mon Sep 17 00:00:00 2001 From: derpystuff <3515180-derpystuff@users.noreply.gitlab.com> Date: Wed, 13 Dec 2023 21:57:47 +0100 Subject: [PATCH 03/13] gemini vision --- commands/message/genai/gemini-vision.js | 80 +++++++++++++++++++++++++ labscore/api/obelisk/endpoints.js | 2 +- labscore/api/obelisk/index.js | 2 +- labscore/utils/statics.js | 5 ++ 4 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 commands/message/genai/gemini-vision.js diff --git a/commands/message/genai/gemini-vision.js b/commands/message/genai/gemini-vision.js new file mode 100644 index 0000000..65a6b23 --- /dev/null +++ b/commands/message/genai/gemini-vision.js @@ -0,0 +1,80 @@ +const { geminiVision } = require("../../../labscore/api/obelisk"); +const { getRecentImage } = require("../../../labscore/utils/attachment"); +const { createEmbed } = require("../../../labscore/utils/embed"); +const { editOrReply } = require("../../../labscore/utils/message"); +const { getUser } = require("../../../labscore/utils/users"); + +const { Permissions } = require("detritus-client/lib/constants"); + +const superagent = require('superagent'); +const { STATIC_ICONS } = require("../../../labscore/utils/statics"); +const { stringwrap } = require("../../../labscore/utils/markdown"); +const { canUseLimitedTestCommands } = require("../../../labscore/utils/testing"); +module.exports = { + name: 'gemini-vision', + label: 'text', + aliases: ['gv'], + metadata: { + description: 'Gemini Vision.', + description_short: 'Pride overlay', + examples: ['gv Which show is this image from?'], + category: 'limited', + usage: 'gemini-vision ' + }, + 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(); + + let image = await getRecentImage(context, 50) + if (!image) return editOrReply(context, createEmbed("warning", context, "No images found.")) + + 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 geminiVision(context, input, image) + + let description = [] + let files = []; + + if(res.response.body.message) return editOrReply(context, createEmbed("error", context, e.response.body.message)) + + console.log(res.response.body) + + 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.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: `Gemini Pro • Generative AI is experimental. Response may be factually incorrect or biased.` + } + })], + 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.`)) + } + } +}; \ No newline at end of file diff --git a/labscore/api/obelisk/endpoints.js b/labscore/api/obelisk/endpoints.js index fb61f0d..a6cae29 100644 --- a/labscore/api/obelisk/endpoints.js +++ b/labscore/api/obelisk/endpoints.js @@ -7,7 +7,7 @@ const ObeliskApi = Object.freeze({ HOST: ObeliskHosts.prod, GOOGLE_BARD: "/parrot/v1/google:bard", - GEMINI_PRO_VISION: "/parrot/v1/google:geminivision", + GEMINI_PRO_VISION: "/parrot/v1/google:geminiVision", SUMMARIZE_WEBPAGES: "/flamingo/v1/web:summarize" }) diff --git a/labscore/api/obelisk/index.js b/labscore/api/obelisk/index.js index 6d7613b..5f7f4cb 100644 --- a/labscore/api/obelisk/index.js +++ b/labscore/api/obelisk/index.js @@ -48,7 +48,7 @@ module.exports.bard = async function(context, input){ } module.exports.geminiVision = async function(context, input, url){ - return await request(ObeliskApi.GOOGLE_BARD, "POST", {}, { + return await request(ObeliskApi.GEMINI_PRO_VISION, "POST", {}, { input, url }) diff --git a/labscore/utils/statics.js b/labscore/utils/statics.js index ebb4f76..804b9b8 100644 --- a/labscore/utils/statics.js +++ b/labscore/utils/statics.js @@ -152,6 +152,10 @@ const Statics = Object.freeze({ file: "brands/_clyde/clyde.png", revision: 0 }, + ai_gemini: { + file: "icons/aiv2/gemini_spark.png", + revision: 0 + }, ai_palm_idle: { file: "icons/core/ico_notice_palm_idle.png", revision: 0 @@ -209,6 +213,7 @@ module.exports.STATIC_ICONS = Object.freeze({ 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_gemini: staticAsset(Statics.icons.ai_gemini), ai_palm_idle: staticAsset(Statics.icons.ai_palm_idle), ai_summary: staticAsset(Statics.icons.ai_summary), warning: staticAsset(Statics.icons.warning) From 2837571614390548e484f8fd243bd7591c934a1f Mon Sep 17 00:00:00 2001 From: derpystuff <3515180-derpystuff@users.noreply.gitlab.com> Date: Wed, 13 Dec 2023 21:59:57 +0100 Subject: [PATCH 04/13] update notice --- commands/message/genai/gemini-vision.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/message/genai/gemini-vision.js b/commands/message/genai/gemini-vision.js index 65a6b23..ba5be7d 100644 --- a/commands/message/genai/gemini-vision.js +++ b/commands/message/genai/gemini-vision.js @@ -66,7 +66,7 @@ module.exports = { }, description: description.join('\n'), footer: { - text: `Gemini Pro • Generative AI is experimental. Response may be factually incorrect or biased.` + text: `Generative AI is experimental • Data submitted to Gemini may be used by Google for training.` } })], files From b4bc83bf962dccca85181f92e37d3f77524910fa Mon Sep 17 00:00:00 2001 From: derpystuff <3515180-derpystuff@users.noreply.gitlab.com> Date: Wed, 13 Dec 2023 22:13:38 +0100 Subject: [PATCH 05/13] show input image in command output --- commands/message/genai/gemini-vision.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/commands/message/genai/gemini-vision.js b/commands/message/genai/gemini-vision.js index ba5be7d..c0ef23e 100644 --- a/commands/message/genai/gemini-vision.js +++ b/commands/message/genai/gemini-vision.js @@ -44,8 +44,6 @@ module.exports = { if(res.response.body.message) return editOrReply(context, createEmbed("error", context, e.response.body.message)) - console.log(res.response.body) - 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.`)) @@ -64,6 +62,9 @@ module.exports = { name: stringwrap(input, 50, false), iconUrl: STATIC_ICONS.ai_gemini }, + thumbnail: { + url: image + }, description: description.join('\n'), footer: { text: `Generative AI is experimental • Data submitted to Gemini may be used by Google for training.` From 7d8ad0700949dbb565798741c77edd44f8a26215 Mon Sep 17 00:00:00 2001 From: derpystuff <3515180-derpystuff@users.noreply.gitlab.com> Date: Wed, 13 Dec 2023 22:17:58 +0100 Subject: [PATCH 06/13] update context window for gemini vision --- commands/message/genai/gemini-vision.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands/message/genai/gemini-vision.js b/commands/message/genai/gemini-vision.js index c0ef23e..68713b0 100644 --- a/commands/message/genai/gemini-vision.js +++ b/commands/message/genai/gemini-vision.js @@ -27,8 +27,8 @@ module.exports = { if(!canUseLimitedTestCommands(context)) return; context.triggerTyping(); - let image = await getRecentImage(context, 50) - if (!image) return editOrReply(context, createEmbed("warning", context, "No images found.")) + let image = await getRecentImage(context, 2) + if (!image) return editOrReply(context, createEmbed("warning", context, "No images found. Reply if you want a specific image.")) if(!args.text) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (text).`)) From 30f00fdbfa5de82aca1ac8564330fbea24a176b5 Mon Sep 17 00:00:00 2001 From: derpystuff <3515180-derpystuff@users.noreply.gitlab.com> Date: Wed, 13 Dec 2023 22:23:09 +0100 Subject: [PATCH 07/13] adjust command further --- commands/message/genai/gemini-vision.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/commands/message/genai/gemini-vision.js b/commands/message/genai/gemini-vision.js index 68713b0..78feeec 100644 --- a/commands/message/genai/gemini-vision.js +++ b/commands/message/genai/gemini-vision.js @@ -15,8 +15,8 @@ module.exports = { label: 'text', aliases: ['gv'], metadata: { - description: 'Gemini Vision.', - description_short: 'Pride overlay', + description: 'Run Gemini Vision on an Image with a custom prompt.', + description_short: 'Run Gemini Vision ', examples: ['gv Which show is this image from?'], category: 'limited', usage: 'gemini-vision ' @@ -27,7 +27,8 @@ module.exports = { if(!canUseLimitedTestCommands(context)) return; context.triggerTyping(); - let image = await getRecentImage(context, 2) + // for the sake of privacy, make the context window one message + let image = await getRecentImage(context, 1) if (!image) return editOrReply(context, createEmbed("warning", context, "No images found. Reply if you want a specific image.")) if(!args.text) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (text).`)) From 9b6ef0da26294f118d086dd4e28ccc1f53dc713e Mon Sep 17 00:00:00 2001 From: derpystuff <3515180-derpystuff@users.noreply.gitlab.com> Date: Wed, 13 Dec 2023 22:36:36 +0100 Subject: [PATCH 08/13] update statics --- labscore/utils/statics.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/labscore/utils/statics.js b/labscore/utils/statics.js index 804b9b8..5143428 100644 --- a/labscore/utils/statics.js +++ b/labscore/utils/statics.js @@ -161,8 +161,8 @@ const Statics = Object.freeze({ revision: 0 }, ai_summary: { - file: "icons/core/ico_notice_summary.png", - revision: 0 + file: "icons/flamingo/web_summary.png", + revision: 1 }, warning: { file: "icons/core/ico_notice_warning.png", From 3b478bd69e7b584d2166587ce1af26d4e4d60113 Mon Sep 17 00:00:00 2001 From: derpystuff <3515180-derpystuff@users.noreply.gitlab.com> Date: Thu, 14 Dec 2023 17:27:45 +0100 Subject: [PATCH 09/13] gemini text --- commands/message/genai/gemini-vision.js | 2 +- commands/message/genai/gemini.js | 71 +++++++++++++++++++++++++ labscore/api/obelisk/endpoints.js | 1 + labscore/api/obelisk/index.js | 6 +++ 4 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 commands/message/genai/gemini.js diff --git a/commands/message/genai/gemini-vision.js b/commands/message/genai/gemini-vision.js index 78feeec..41ea5c6 100644 --- a/commands/message/genai/gemini-vision.js +++ b/commands/message/genai/gemini-vision.js @@ -46,7 +46,7 @@ module.exports = { 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, `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) diff --git a/commands/message/genai/gemini.js b/commands/message/genai/gemini.js new file mode 100644 index 0000000..0ed7509 --- /dev/null +++ b/commands/message/genai/gemini.js @@ -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 ' + }, + 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.`)) + } + } +}; \ No newline at end of file diff --git a/labscore/api/obelisk/endpoints.js b/labscore/api/obelisk/endpoints.js index a6cae29..1694111 100644 --- a/labscore/api/obelisk/endpoints.js +++ b/labscore/api/obelisk/endpoints.js @@ -7,6 +7,7 @@ const ObeliskApi = Object.freeze({ HOST: ObeliskHosts.prod, GOOGLE_BARD: "/parrot/v1/google:bard", + GEMINI_PRO: "/parrot/v1/google:gemini", GEMINI_PRO_VISION: "/parrot/v1/google:geminiVision", SUMMARIZE_WEBPAGES: "/flamingo/v1/web:summarize" diff --git a/labscore/api/obelisk/index.js b/labscore/api/obelisk/index.js index 5f7f4cb..a4161df 100644 --- a/labscore/api/obelisk/index.js +++ b/labscore/api/obelisk/index.js @@ -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){ return await request(ObeliskApi.GEMINI_PRO_VISION, "POST", {}, { input, From 641ab48053f3298c5bd835d5a918bfc4fef74148 Mon Sep 17 00:00:00 2001 From: derpystuff <3515180-derpystuff@users.noreply.gitlab.com> Date: Thu, 14 Dec 2023 21:46:33 +0100 Subject: [PATCH 10/13] migrate ai commands to obelisk --- commands/message/limited/chat.js | 23 ++++++++++------------- commands/message/limited/clyde.js | 13 +++---------- commands/message/limited/disstrack.js | 18 ++++++------------ commands/message/limited/palm.js | 15 ++++----------- labscore/api/obelisk/endpoints.js | 8 ++++++-- labscore/api/obelisk/index.js | 25 +++++++++++++++++++++++-- 6 files changed, 52 insertions(+), 50 deletions(-) diff --git a/commands/message/limited/chat.js b/commands/message/limited/chat.js index 16204a0..c614152 100644 --- a/commands/message/limited/chat.js +++ b/commands/message/limited/chat.js @@ -8,6 +8,7 @@ const superagent = require('superagent') const { iconPill, stringwrap, smallIconPill } = require('../../../labscore/utils/markdown') const { Permissions } = require("detritus-client/lib/constants"); +const { chatgpt } = require('../../../labscore/api/obelisk'); const MODELS = { "chatgpt": { @@ -78,27 +79,23 @@ module.exports = { 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: MODELS[model.toLowerCase()].id - }) + let res; + if(model.toLowerCase() == "chatgpt"){ + res = await chatgpt(context, prompt, input) + } else if (model.toLowerCase() == "gpt4"){ + res = await chatgpt(context, prompt, input) + } let description = [] let files = []; - if(!res.body.output) throw "Unable to generate response" + if(!res.response.body.output) throw "Unable to generate response" - if(res.body.output.length <= 4000) description.push(res.body.output) + if(res.response.body.output.length <= 4000) description.push(res.response.body.output) else { files.push({ filename: `chat.${Date.now().toString(36)}.txt`, - value: Buffer.from(res.body.output) + value: Buffer.from(res.response.body.output) }) } diff --git a/commands/message/limited/clyde.js b/commands/message/limited/clyde.js index 5bc2b0d..9f0aff0 100644 --- a/commands/message/limited/clyde.js +++ b/commands/message/limited/clyde.js @@ -9,6 +9,7 @@ const { iconPill, stringwrap } = require('../../../labscore/utils/markdown') const { Permissions } = require("detritus-client/lib/constants"); const { getUser } = require('../../../labscore/utils/users'); +const { chatgpt } = require('../../../labscore/api/obelisk'); const LOADING_QUIPS = [ "Crunching the data, one byte at a time...", @@ -86,16 +87,8 @@ Current time: ${new Date().toLocaleDateString('en-us', { weekday:"long", year:"n 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 res = await chatgpt(context, prompt, input); + res = res.response; let description = [] let files = []; diff --git a/commands/message/limited/disstrack.js b/commands/message/limited/disstrack.js index a585044..6a6209e 100644 --- a/commands/message/limited/disstrack.js +++ b/commands/message/limited/disstrack.js @@ -6,7 +6,8 @@ const { codeblock, iconPill, smallIconPill } = require('../../../labscore/utils/ const { Permissions } = require("detritus-client/lib/constants"); const { canUseLimitedTestCommands } = require('../../../labscore/utils/testing') -const { STATICS } = require('../../../labscore/utils/statics') +const { STATICS } = require('../../../labscore/utils/statics'); +const { chatgpt } = require('../../../labscore/api/obelisk'); module.exports = { name: 'disstrack', @@ -24,18 +25,11 @@ module.exports = { context.triggerTyping(); if(!args.text) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (text).`)) try{ - await editOrReply(context, createEmbed("ai", context, "Generating response...")) + await editOrReply(context, createEmbed("ai", context, "Spitting bars...")) - let res = await superagent.post(`${process.env.AI_SERVER}/openai`) - .set({ - Authorization: process.env.AI_SERVER_KEY - }) - .send({ - prompt: "Write a disstrack about the subject the user supplies. The disstrack should have at least two verses and a chorus.", - input: [args.text], - temperature: 0.6, - model: "CHATGPT" - }) + let res = await chatgpt(context, "Write a disstrack about the subject the user supplies. The disstrack should have at least one verse and a chorus.", args.text); + res = res.response; + return editOrReply(context, createEmbed("default", context, { description: smallIconPill("generative_ai", args.text) + '\n' + codeblock("ansi", [res.body.output.substr(0, 2020 - args.text.length)]), footer: { diff --git a/commands/message/limited/palm.js b/commands/message/limited/palm.js index 7275078..df7d90c 100644 --- a/commands/message/limited/palm.js +++ b/commands/message/limited/palm.js @@ -8,6 +8,7 @@ const superagent = require('superagent') const { iconPill, stringwrap, smallIconPill } = require('../../../labscore/utils/markdown') const { Permissions } = require("detritus-client/lib/constants"); +const { palm2 } = require('../../../labscore/api/obelisk'); module.exports = { name: 'palm', @@ -56,17 +57,9 @@ module.exports = { try{ await editOrReply(context, createEmbed("ai_custom", context, STATIC_ICONS.ai_palm_idle)) - let res = await superagent.post(`${process.env.AI_SERVER}/google/palm2/chat`) - .set({ - Authorization: process.env.AI_SERVER_KEY - }) - .send({ - prompt, - input: [input], - temperature, - model - }) - + let res = await palm2(context, prompt, input) + res = res.response; + let description = [] let files = []; diff --git a/labscore/api/obelisk/endpoints.js b/labscore/api/obelisk/endpoints.js index 1694111..3b19de1 100644 --- a/labscore/api/obelisk/endpoints.js +++ b/labscore/api/obelisk/endpoints.js @@ -7,8 +7,12 @@ const ObeliskApi = Object.freeze({ HOST: ObeliskHosts.prod, GOOGLE_BARD: "/parrot/v1/google:bard", - GEMINI_PRO: "/parrot/v1/google:gemini", - GEMINI_PRO_VISION: "/parrot/v1/google:geminiVision", + GOOGLE_GEMINI_PRO: "/parrot/v1/google:gemini", + GOOGLE_GEMINI_PRO_VISION: "/parrot/v1/google:geminiVision", + GOOGLE_PALM2: "/parrot/v1/google:palm2", + + OPENAI_CHATGPT: "/parrot/v1/openai:chatgpt", + OPENAI_GPT4: "/parrot/v1/openai:gpt4", SUMMARIZE_WEBPAGES: "/flamingo/v1/web:summarize" }) diff --git a/labscore/api/obelisk/index.js b/labscore/api/obelisk/index.js index a4161df..d670e5d 100644 --- a/labscore/api/obelisk/index.js +++ b/labscore/api/obelisk/index.js @@ -48,18 +48,39 @@ module.exports.bard = async function(context, input){ } module.exports.gemini = async function(context, prompt){ - return await request(ObeliskApi.GEMINI_PRO, "POST", {}, { + return await request(ObeliskApi.GOOGLE_GEMINI_PRO, "POST", {}, { prompt }) } module.exports.geminiVision = async function(context, input, url){ - return await request(ObeliskApi.GEMINI_PRO_VISION, "POST", {}, { + return await request(ObeliskApi.GOOGLE_GEMINI_PRO_VISION, "POST", {}, { input, url }) } +module.exports.palm2 = async function(context, prompt, input){ + return await request(ObeliskApi.GOOGLE_PALM2, "POST", {}, { + prompt, + input + }) +} + +module.exports.chatgpt = async function(context, prompt, input){ + return await request(ObeliskApi.OPENAI_CHATGPT, "POST", {}, { + prompt, + input + }) +} + +module.exports.gpt4 = async function(context, prompt, input){ + return await request(ObeliskApi.OPENAI_GPT4, "POST", {}, { + prompt, + input + }) +} + // FLAMINGO module.exports.summarizeWebpage = async function(context, url){ return await request(ObeliskApi.SUMMARIZE_WEBPAGES, "POST", {}, { From 699327266b76e154fa8b3152b82926dbb8a01e50 Mon Sep 17 00:00:00 2001 From: derpystuff <3515180-derpystuff@users.noreply.gitlab.com> Date: Fri, 15 Dec 2023 15:19:40 +0100 Subject: [PATCH 11/13] fix newlines --- commands/message/limited/bard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/message/limited/bard.js b/commands/message/limited/bard.js index e41fa78..33b123f 100644 --- a/commands/message/limited/bard.js +++ b/commands/message/limited/bard.js @@ -53,7 +53,7 @@ module.exports = { if(!res.body.drafts || res.body.drafts?.length <= 1) return editOrReply(context, { embeds:[createEmbed("defaultNoFooter", context, { author: { - name: stringwrap(args.text, 50), + name: stringwrap(args.text, 50, false), iconUrl: STATIC_ICONS.ai_bard_idle }, description: description.join('\n'), From 102d8956971725e7b03dd7cec68ceec70a6b71a6 Mon Sep 17 00:00:00 2001 From: derpystuff <3515180-derpystuff@users.noreply.gitlab.com> Date: Fri, 15 Dec 2023 18:03:38 +0100 Subject: [PATCH 12/13] replace newlines with space --- labscore/utils/markdown.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labscore/utils/markdown.js b/labscore/utils/markdown.js index bc79563..2b01c7f 100644 --- a/labscore/utils/markdown.js +++ b/labscore/utils/markdown.js @@ -30,7 +30,7 @@ module.exports.timestamp = function(time, flag = "t"){ } module.exports.stringwrap = function(content = "", length, newlines = true){ - if(!newlines) content = content.replace(/\n/, '') + if(!newlines) content = content.replace(/\n/, ' ') if(content.length > length) return content.substr(0, length) + '...'; return content; } From 7a28cef7751d398ab096d88c3d9ea673610d6e8e Mon Sep 17 00:00:00 2001 From: derpystuff <3515180-derpystuff@users.noreply.gitlab.com> Date: Sat, 16 Dec 2023 23:18:32 +0100 Subject: [PATCH 13/13] add labels to gemini commands --- commands/message/genai/gemini-vision.js | 4 ++-- commands/message/genai/gemini.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/commands/message/genai/gemini-vision.js b/commands/message/genai/gemini-vision.js index 41ea5c6..a692d23 100644 --- a/commands/message/genai/gemini-vision.js +++ b/commands/message/genai/gemini-vision.js @@ -8,14 +8,14 @@ const { Permissions } = require("detritus-client/lib/constants"); const superagent = require('superagent'); const { STATIC_ICONS } = require("../../../labscore/utils/statics"); -const { stringwrap } = require("../../../labscore/utils/markdown"); +const { stringwrap, iconPill, smallIconPill } = require("../../../labscore/utils/markdown"); const { canUseLimitedTestCommands } = require("../../../labscore/utils/testing"); module.exports = { name: 'gemini-vision', label: 'text', aliases: ['gv'], metadata: { - description: 'Run Gemini Vision on an Image with a custom prompt.', + description: `${iconPill("generative_ai", "LIMITED TESTING")}\n${smallIconPill("reply", "Supports Replies")}\n\nRun Gemini Vision on an Image with a custom prompt.`, description_short: 'Run Gemini Vision ', examples: ['gv Which show is this image from?'], category: 'limited', diff --git a/commands/message/genai/gemini.js b/commands/message/genai/gemini.js index 0ed7509..121082a 100644 --- a/commands/message/genai/gemini.js +++ b/commands/message/genai/gemini.js @@ -5,14 +5,14 @@ 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 { stringwrap, iconPill, smallIconPill } = 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: `${iconPill("generative_ai", "LIMITED TESTING")}\n${smallIconPill("reply", "Supports Replies")}\n\nRun 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',