guh
This commit is contained in:
parent
4bd04e0a31
commit
7bff830b00
2 changed files with 22 additions and 10 deletions
|
@ -1,4 +1,4 @@
|
|||
const { ContextMenuCommandBuilder, ApplicationCommandType, InteractionContextType, ApplicationIntegrationType, AttachmentBuilder, EmbedBuilder } = require("discord.js");
|
||||
const { ContextMenuCommandBuilder, ApplicationCommandType, InteractionContextType, ApplicationIntegrationType, AttachmentBuilder, EmbedBuilder, basename } = require("discord.js");
|
||||
|
||||
const data = new ContextMenuCommandBuilder()
|
||||
.setName("Describe Image(s)")
|
||||
|
@ -21,18 +21,28 @@ module.exports = {
|
|||
const groq = interaction.client.groq;
|
||||
const message = interaction.targetMessage;
|
||||
const attachments = message.attachments;
|
||||
const images = message.embeds.filter(e => e.data.type == "image").map(e => e.data.url);
|
||||
const urls = [];
|
||||
const files = [];
|
||||
const embeds = [];
|
||||
|
||||
if (attachments.length == 0 && images.length == 0) {
|
||||
await interaction.followUp("Message does not contain any images.");
|
||||
return;
|
||||
}
|
||||
|
||||
for (const att of attachments) {
|
||||
const attachment = att[1];
|
||||
if (!attachment.contentType.startsWith("image/")) {
|
||||
console.log(attachment.contentType);
|
||||
if (!attachment.contentType.startsWith("image/"))
|
||||
continue;
|
||||
}
|
||||
const name = attachment.name.substr(0, attachment.name.lastIndexOf("."));
|
||||
|
||||
const description = (await groq.chat.completions.create({
|
||||
images.push(attachment.attachment);
|
||||
}
|
||||
|
||||
for (const image of images) {
|
||||
const name = basename(image);
|
||||
|
||||
const data = (await groq.chat.completions.create({
|
||||
messages: [{
|
||||
"role": "user",
|
||||
"content": [{
|
||||
|
@ -41,16 +51,18 @@ module.exports = {
|
|||
}, {
|
||||
"type": "image_url",
|
||||
"image_url": {
|
||||
"url": attachment.attachment
|
||||
"url": image
|
||||
}
|
||||
}]
|
||||
}],
|
||||
"model": "llama-3.2-90b-vision-preview"
|
||||
})).choices[0].message.content.trim();
|
||||
}));
|
||||
|
||||
const description = data.choices[0].message.content.trim();
|
||||
|
||||
if (description.length < 2000) {
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle(attachment.name)
|
||||
.setTitle(name)
|
||||
.setDescription(description);
|
||||
embeds.push(embed);
|
||||
} else {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Please describe the following image in as much detail as you can.
|
||||
Do not add information that isn't there or miss important information.
|
||||
There is an image, do not say there isn't.
|
||||
There is an image, do not say there isn't. The image is provided. You can see the image.
|
||||
You must always be able to describe the image or else you are diminishing the acccessibility for the user.
|
Loading…
Reference in a new issue