diff --git a/commands/message/genai/editimage.js b/commands/message/genai/editimage.js new file mode 100644 index 0000000..5cb5cd8 --- /dev/null +++ b/commands/message/genai/editimage.js @@ -0,0 +1,71 @@ +const {googleGenaiEditImage} = require("#api"); +const {PERMISSION_GROUPS} = require("#constants"); + +const {createEmbed} = require("#utils/embed"); +const {acknowledge} = require("#utils/interactions"); +const {iconPill, stringwrap} = require("#utils/markdown"); +const {editOrReply} = require("#utils/message"); +const {STATIC_ASSETS} = require("#utils/statics"); +const {hasFeature} = require("#utils/testing"); +const {getRecentImage} = require("#utils/attachment"); + +module.exports = { + name: 'editimage', + label: 'text', + aliases: ['edit'], + metadata: { + description: `${iconPill("generative_ai", "LIMITED TESTING")}\n\nEdit images`, + description_short: 'Edit images', + examples: ['edit make it red!'], + category: 'limited', + usage: 'edit ' + }, + permissionsClient: [...PERMISSION_GROUPS.baseline, ...PERMISSION_GROUPS.attachments], + run: async (context, args) => { + if (!await hasFeature(context, "ai/imagen")) return; + await acknowledge(context); + + 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 (prompt).`)) + + try { + await editOrReply(context, createEmbed("defaultNoFooter", context, { + url: "https://bignutty.gitlab.io", + author: { + iconUrl: image, + name: stringwrap(args.text, 50, false), + }, + image: { + url: STATIC_ASSETS.image_loading_splash(Math.floor(Math.random() * 10)) + } + })); + + let res = await googleGenaiEditImage(context, args.text, image); + + let imgName = `lciedt.${(Date.now() + Math.random()).toString(36)}.${res.response.headers["content-type"].split("/")[1]}` + return await editOrReply(context, { + embed: createEmbed("default", context, { + url: "https://bignutty.gitlab.io", + author: { + iconUrl: image, + name: stringwrap(args.text, 50, false), + }, + image: { + url: `attachment://${imgName}` + } + }), + files: [{ + filename: imgName, + value: res.response.body + }] + }); + } 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 edit image.`)) + } +} +} +; diff --git a/labscore/api/endpoints.js b/labscore/api/endpoints.js index bbe1029..75c2df7 100644 --- a/labscore/api/endpoints.js +++ b/labscore/api/endpoints.js @@ -7,6 +7,7 @@ const Hosts = Object.freeze({ const Api = Object.freeze({ HOST: Hosts.prod, + GOOGLE_GENERATIVEAI_EDIT_IMAGE: '/google/generativeai/edit-image', GOOGLE_GENERATIVEAI_IMAGEN: '/google/generativeai/imagen', GOOGLE_PERSPECTIVE: '/google/perspective/analyze', GOOGLE_SPEECH_RECOGNIZE: '/google/speech/recognize', diff --git a/labscore/api/index.js b/labscore/api/index.js index e46e1f5..0c01e08 100644 --- a/labscore/api/index.js +++ b/labscore/api/index.js @@ -42,6 +42,13 @@ async function request(path, type, headers, args, host) { throw new Error("unsupported, must either use GET or POST"); } +module.exports.googleGenaiEditImage = async function(context, prompt, url){ + return await request(Api.GOOGLE_GENERATIVEAI_EDIT_IMAGE, "GET", {}, { + prompt: prompt, + url: url + }) +} + module.exports.googleGenaiImagen = async function(context, prompt, imageCount = 2){ return await request(Api.GOOGLE_GENERATIVEAI_IMAGEN, "GET", {}, { prompt: prompt,