Content-Length: 431083 | pFad | https://github.com/TecEash1/Taurus/commit/4e315045ca51139232c7ca03c5f2db10dbe221b6

4C Adds file viewing support · TecEash1/Taurus@4e31504 · GitHub
Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4e31504

Browse files
committedMay 7, 2024
Adds file viewing support
1 parent ba696c9 commit 4e31504

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
 

‎events/taurusai.js

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const {
1414
handleResponse,
1515
checkGeminiApiKey,
1616
fetchThreadMessages,
17+
processAttachments,
1718
} = require("../utils");
1819
const genAI = new GoogleGenerativeAI(Gemini_API_KEY);
1920

@@ -25,6 +26,8 @@ module.exports = {
2526
return;
2627
if ([18, 21].includes(message.type)) return;
2728

29+
const attachments = await processAttachments(message);
30+
2831
let userQuestion;
2932
let messageDeleted;
3033
let threadMessages = [];
@@ -97,6 +100,8 @@ module.exports = {
97100
instruction += ` The user's status/presence is currently:\n${status_devices}`;
98101
}
99102

103+
userQuestion += `\n\n${attachments}`;
104+
100105
const generationConfig = {
101106
maxOutputTokens: 750,
102107
};

‎utils.js

+39
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const { HarmCategory, HarmBlockThreshold } = require("@google/generative-ai");
22
const { EmbedBuilder, DiscordAPIError } = require("discord.js");
3+
const axios = require("axios");
34

45
function botInGuild(interaction) {
56
const botGuilds = interaction.client.guilds.cache;
@@ -241,7 +242,9 @@ async function fetchThreadMessages(Gemini_API_KEY, message) {
241242
: "user";
242243
let content = currentMessage.content;
243244
if (sender === "user") {
245+
const attachments = await processAttachments(currentMessage);
244246
content = content.replace(/<@\d+>\s*/, "");
247+
content += `\n\n${attachments}`;
245248
} else if (
246249
sender === "model" &&
247250
currentMessage.embeds.length > 0 &&
@@ -275,11 +278,47 @@ async function fetchThreadMessages(Gemini_API_KEY, message) {
275278
return { userQuestion, threadMessages, messageDeleted };
276279
}
277280

281+
async function processAttachments(message) {
282+
let attachmentsContent = "";
283+
284+
if (message.attachments.size > 0) {
285+
let hasTextPlainAttachment = false;
286+
287+
const promises = message.attachments.map(async (attachment) => {
288+
if (attachment.contentType === "text/plain; charset=utf-8") {
289+
hasTextPlainAttachment = true;
290+
const name = attachment.name;
291+
const url = attachment.url;
292+
293+
try {
294+
const result = await axios.get(url);
295+
const attachmentContent = result.data;
296+
297+
attachmentsContent += `Name: ${name}\nContent: ${attachmentContent}\n\n`;
298+
} catch (error) {
299+
console.error(`Failed to retrieve content from ${url}: ${error}`);
300+
}
301+
}
302+
});
303+
304+
await Promise.all(promises);
305+
306+
if (hasTextPlainAttachment) {
307+
attachmentsContent =
308+
"Below are the following files attached to my message:\n\n" +
309+
attachmentsContent;
310+
}
311+
}
312+
313+
return attachmentsContent;
314+
}
315+
278316
module.exports = {
279317
botInGuild,
280318
safetySettings,
281319
handleGeminiError,
282320
handleResponse,
283321
checkGeminiApiKey,
284322
fetchThreadMessages,
323+
processAttachments,
285324
};

0 commit comments

Comments
 (0)
Failed to load comments.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/TecEash1/Taurus/commit/4e315045ca51139232c7ca03c5f2db10dbe221b6

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy