mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-07 13:43:06 -04:00
add editimage
This commit is contained in:
parent
da5da4c673
commit
5e3235019c
3 changed files with 79 additions and 0 deletions
71
commands/message/genai/editimage.js
Normal file
71
commands/message/genai/editimage.js
Normal file
|
@ -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 <attachment> <prompt>'
|
||||||
|
},
|
||||||
|
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.`))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
;
|
|
@ -7,6 +7,7 @@ const Hosts = Object.freeze({
|
||||||
const Api = Object.freeze({
|
const Api = Object.freeze({
|
||||||
HOST: Hosts.prod,
|
HOST: Hosts.prod,
|
||||||
|
|
||||||
|
GOOGLE_GENERATIVEAI_EDIT_IMAGE: '/google/generativeai/edit-image',
|
||||||
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',
|
||||||
|
|
|
@ -42,6 +42,13 @@ async function request(path, type, headers, args, host) {
|
||||||
throw new Error("unsupported, must either use GET or POST");
|
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){
|
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,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue