apexify.js 3.3.6 → 3.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- package/.github/dependabot.yml +7 -0
- package/.tsbuildinfo +1 -1
- package/CODE_OF_CONDUCT.md +128 -0
- package/LICENSE +21 -0
- package/README.md +27 -21
- package/SECURITY.md +20 -0
- package/change logs.md +1 -1
- package/examples/barchart.txt +0 -2
- package/examples/linechart.txt +0 -2
- package/lib/ai/ApexAI.ts +116 -85
- package/lib/ai/functions/draw.ts +67 -69
- package/lib/ai/functions/generateVoiceResponse.ts +15 -22
- package/lib/ai/functions/readImagess.ts +6 -6
- package/lib/ai/functions/typeWriter.ts +0 -2
- package/lib/canvas/ApexPainter.ts +75 -80
- package/lib/canvas/utils/bg.ts +7 -4
- package/lib/canvas/utils/charts.ts +37 -22
- package/lib/canvas/utils/general functions.ts +71 -53
- package/lib/canvas/utils/types.ts +14 -7
- package/lib/index.ts +6 -6
- package/package.json +3 -3
- package/dist/ai/ApexAI.d.ts +0 -62
- package/dist/ai/ApexAI.d.ts.map +0 -1
- package/dist/ai/ApexAI.js +0 -421
- package/dist/ai/ApexAI.js.map +0 -1
- package/dist/ai/buttons/drawMenu.d.ts +0 -3
- package/dist/ai/buttons/drawMenu.d.ts.map +0 -1
- package/dist/ai/buttons/drawMenu.js +0 -274
- package/dist/ai/buttons/drawMenu.js.map +0 -1
- package/dist/ai/buttons/tools.d.ts +0 -3
- package/dist/ai/buttons/tools.d.ts.map +0 -1
- package/dist/ai/buttons/tools.js +0 -445
- package/dist/ai/buttons/tools.js.map +0 -1
- package/dist/ai/functions/aivoice.d.ts +0 -1
- package/dist/ai/functions/aivoice.d.ts.map +0 -1
- package/dist/ai/functions/aivoice.js +0 -2
- package/dist/ai/functions/aivoice.js.map +0 -1
- package/dist/ai/functions/chunkString.d.ts +0 -2
- package/dist/ai/functions/chunkString.d.ts.map +0 -1
- package/dist/ai/functions/chunkString.js +0 -8
- package/dist/ai/functions/chunkString.js.map +0 -1
- package/dist/ai/functions/draw.d.ts +0 -3
- package/dist/ai/functions/draw.d.ts.map +0 -1
- package/dist/ai/functions/draw.js +0 -387
- package/dist/ai/functions/draw.js.map +0 -1
- package/dist/ai/functions/generateVoiceResponse.d.ts +0 -3
- package/dist/ai/functions/generateVoiceResponse.d.ts.map +0 -1
- package/dist/ai/functions/generateVoiceResponse.js +0 -158
- package/dist/ai/functions/generateVoiceResponse.js.map +0 -1
- package/dist/ai/functions/imageReader.d.ts +0 -3
- package/dist/ai/functions/imageReader.d.ts.map +0 -1
- package/dist/ai/functions/imageReader.js +0 -23
- package/dist/ai/functions/imageReader.js.map +0 -1
- package/dist/ai/functions/readFiles.d.ts +0 -3
- package/dist/ai/functions/readFiles.d.ts.map +0 -1
- package/dist/ai/functions/readFiles.js +0 -62
- package/dist/ai/functions/readFiles.js.map +0 -1
- package/dist/ai/functions/readImagess.d.ts +0 -2
- package/dist/ai/functions/readImagess.d.ts.map +0 -1
- package/dist/ai/functions/readImagess.js +0 -48
- package/dist/ai/functions/readImagess.js.map +0 -1
- package/dist/ai/functions/shouldDrawImage.d.ts +0 -2
- package/dist/ai/functions/shouldDrawImage.d.ts.map +0 -1
- package/dist/ai/functions/shouldDrawImage.js +0 -12
- package/dist/ai/functions/shouldDrawImage.js.map +0 -1
- package/dist/ai/functions/typeWriter.d.ts +0 -2
- package/dist/ai/functions/typeWriter.d.ts.map +0 -1
- package/dist/ai/functions/typeWriter.js +0 -24
- package/dist/ai/functions/typeWriter.js.map +0 -1
- package/dist/ai/models.d.ts +0 -9
- package/dist/ai/models.d.ts.map +0 -1
- package/dist/ai/models.js +0 -575
- package/dist/ai/models.js.map +0 -1
- package/dist/ai/utils.d.ts +0 -11
- package/dist/ai/utils.d.ts.map +0 -1
- package/dist/ai/utils.js +0 -24
- package/dist/ai/utils.js.map +0 -1
- package/dist/canvas/ApexPainter.d.ts +0 -38
- package/dist/canvas/ApexPainter.d.ts.map +0 -1
- package/dist/canvas/ApexPainter.js +0 -439
- package/dist/canvas/ApexPainter.js.map +0 -1
- package/dist/canvas/utils/bg.d.ts +0 -23
- package/dist/canvas/utils/bg.d.ts.map +0 -1
- package/dist/canvas/utils/bg.js +0 -74
- package/dist/canvas/utils/bg.js.map +0 -1
- package/dist/canvas/utils/charts.d.ts +0 -9
- package/dist/canvas/utils/charts.d.ts.map +0 -1
- package/dist/canvas/utils/charts.js +0 -454
- package/dist/canvas/utils/charts.js.map +0 -1
- package/dist/canvas/utils/circular.d.ts +0 -10
- package/dist/canvas/utils/circular.d.ts.map +0 -1
- package/dist/canvas/utils/circular.js +0 -22
- package/dist/canvas/utils/circular.js.map +0 -1
- package/dist/canvas/utils/customLines.d.ts +0 -2
- package/dist/canvas/utils/customLines.d.ts.map +0 -1
- package/dist/canvas/utils/customLines.js +0 -50
- package/dist/canvas/utils/customLines.js.map +0 -1
- package/dist/canvas/utils/general functions.d.ts +0 -21
- package/dist/canvas/utils/general functions.d.ts.map +0 -1
- package/dist/canvas/utils/general functions.js +0 -391
- package/dist/canvas/utils/general functions.js.map +0 -1
- package/dist/canvas/utils/imageProperties.d.ts +0 -60
- package/dist/canvas/utils/imageProperties.d.ts.map +0 -1
- package/dist/canvas/utils/imageProperties.js +0 -331
- package/dist/canvas/utils/imageProperties.js.map +0 -1
- package/dist/canvas/utils/radius.d.ts +0 -10
- package/dist/canvas/utils/radius.d.ts.map +0 -1
- package/dist/canvas/utils/radius.js +0 -31
- package/dist/canvas/utils/radius.js.map +0 -1
- package/dist/canvas/utils/textProperties.d.ts +0 -18
- package/dist/canvas/utils/textProperties.d.ts.map +0 -1
- package/dist/canvas/utils/textProperties.js +0 -67
- package/dist/canvas/utils/textProperties.js.map +0 -1
- package/dist/canvas/utils/types.d.ts +0 -414
- package/dist/canvas/utils/types.d.ts.map +0 -1
- package/dist/canvas/utils/types.js +0 -5
- package/dist/canvas/utils/types.js.map +0 -1
- package/dist/canvas/utils/utils.d.ts +0 -20
- package/dist/canvas/utils/utils.d.ts.map +0 -1
- package/dist/canvas/utils/utils.js +0 -48
- package/dist/canvas/utils/utils.js.map +0 -1
- package/dist/index.d.ts +0 -11
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -65
- package/dist/index.js.map +0 -1
- package/dist/utils.d.ts +0 -12
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -12
- package/dist/utils.js.map +0 -1
package/SECURITY.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported Versions
|
|
4
|
+
|
|
5
|
+
Use this section to tell people about which versions of your project are
|
|
6
|
+
currently being supported with security updates.
|
|
7
|
+
|
|
8
|
+
| Version | Supported |
|
|
9
|
+
| ------- | ------------------ |
|
|
10
|
+
| >v1.x.x | :white_check_mark: |
|
|
11
|
+
| >v2.x.x | :white_check_mark: |
|
|
12
|
+
| >v3.3.x | :white_check_mark: |
|
|
13
|
+
|
|
14
|
+
## Reporting a Vulnerability
|
|
15
|
+
|
|
16
|
+
Use this section to tell people how to report a vulnerability.
|
|
17
|
+
|
|
18
|
+
Tell them where to go, how often they can expect to get an update on a
|
|
19
|
+
reported vulnerability, what to expect if the vulnerability is accepted or
|
|
20
|
+
declined, etc.
|
package/change logs.md
CHANGED
package/examples/barchart.txt
CHANGED
|
@@ -14,7 +14,6 @@ const data = {
|
|
|
14
14
|
},
|
|
15
15
|
bg: {
|
|
16
16
|
image: 'https://png.pngtree.com/thumb_back/fh260/background/20211118/pngtree-financial-technology-data-graph-image_908921.jpg',
|
|
17
|
-
baseDir: __dirname,
|
|
18
17
|
bgColor: 'darkgray'
|
|
19
18
|
},
|
|
20
19
|
grid: {
|
|
@@ -58,7 +57,6 @@ const data = {
|
|
|
58
57
|
'blue': 'Label 3',
|
|
59
58
|
'yellow': 'Lable 4'
|
|
60
59
|
},
|
|
61
|
-
keyColor: '',
|
|
62
60
|
xTitle: 'X Axis Title',
|
|
63
61
|
yTitle: 'Y Axis Title',
|
|
64
62
|
labelStyle: {
|
package/examples/linechart.txt
CHANGED
|
@@ -79,13 +79,11 @@ const data = {
|
|
|
79
79
|
lineWidth: 3,
|
|
80
80
|
},
|
|
81
81
|
canvas: {
|
|
82
|
-
bgColor: 'black',
|
|
83
82
|
fontColor: 'white',
|
|
84
83
|
fontSize: 16,
|
|
85
84
|
width: 800,
|
|
86
85
|
height: 600,
|
|
87
86
|
image: 'image url or path if u dont want a bg color',
|
|
88
|
-
baseDir: __dirname // need to be added if u using a local path image
|
|
89
87
|
}
|
|
90
88
|
}
|
|
91
89
|
};
|
package/lib/ai/ApexAI.ts
CHANGED
|
@@ -10,12 +10,11 @@ import {
|
|
|
10
10
|
typeWriter,
|
|
11
11
|
readImage,
|
|
12
12
|
} from "./utils";
|
|
13
|
-
import axios from "axios";
|
|
14
13
|
import {
|
|
15
14
|
ModalBuilder,
|
|
16
15
|
TextInputBuilder,
|
|
17
16
|
TextInputStyle,
|
|
18
|
-
ActionRowBuilder
|
|
17
|
+
ActionRowBuilder
|
|
19
18
|
} from "discord.js";
|
|
20
19
|
import { filters } from "./buttons/tools";
|
|
21
20
|
import { imageTools } from "./buttons/drawMenu";
|
|
@@ -406,7 +405,6 @@ export async function ApexAI (message: any, aiOptions: Options) {
|
|
|
406
405
|
await typeWriter(message.channel, part, speed, delay);
|
|
407
406
|
}
|
|
408
407
|
}
|
|
409
|
-
|
|
410
408
|
} else {
|
|
411
409
|
if (response.length <= 2000) {
|
|
412
410
|
await message.reply({
|
|
@@ -479,106 +477,139 @@ export async function ApexAI (message: any, aiOptions: Options) {
|
|
|
479
477
|
}
|
|
480
478
|
|
|
481
479
|
export async function gemmaAi_4(prompt: string) {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
480
|
+
try {
|
|
481
|
+
const response = await fetch('https://api-inference.huggingface.co/models/google/gemma-7b-it', {
|
|
482
|
+
method: 'POST',
|
|
483
|
+
headers: {
|
|
484
|
+
'Content-Type': 'application/json',
|
|
485
|
+
'Authorization': 'Bearer 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'
|
|
486
|
+
},
|
|
487
|
+
body: JSON.stringify({ inputs: prompt })
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
if (!response.ok) {
|
|
491
|
+
throw new Error('Network response was not ok');
|
|
490
492
|
}
|
|
493
|
+
|
|
494
|
+
const responseData = await response.json();
|
|
495
|
+
return responseData[0].generated_text;
|
|
496
|
+
} catch (error: any) {
|
|
497
|
+
console.error('Error fetching response:', error.message);
|
|
498
|
+
return null;
|
|
499
|
+
}
|
|
491
500
|
}
|
|
492
501
|
|
|
493
502
|
export async function gemmaAi_3(prompt: string) {
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
503
|
+
try {
|
|
504
|
+
const response = await fetch('https://api-inference.huggingface.co/models/google/gemma-2b-it', {
|
|
505
|
+
method: 'POST',
|
|
506
|
+
headers: {
|
|
507
|
+
'Content-Type': 'application/json',
|
|
508
|
+
'Authorization': 'Bearer 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'
|
|
509
|
+
},
|
|
510
|
+
body: JSON.stringify({ inputs: prompt })
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
if (!response.ok) {
|
|
514
|
+
throw new Error('Network response was not ok');
|
|
515
|
+
}
|
|
504
516
|
|
|
517
|
+
const responseData = await response.json();
|
|
518
|
+
return responseData[0].generated_text;
|
|
519
|
+
} catch (error: any) {
|
|
520
|
+
console.error('Error fetching response:', error.message);
|
|
521
|
+
return null;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
505
524
|
export async function apexai(prompt: string) {
|
|
506
|
-
|
|
525
|
+
try {
|
|
507
526
|
const messages = [
|
|
508
|
-
|
|
527
|
+
{"role": "user", "content": `${prompt}`}
|
|
509
528
|
];
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
const generatedText = response.data[0].generated_text;
|
|
529
|
+
const formattedMessages = messages.map(message => `[${message.role}] ${message.content}`).join('\n');
|
|
530
|
+
|
|
531
|
+
const response = await fetch('https://api-inference.huggingface.co/models/mistralai/Mixtral-8x7B-Instruct-v0.1', {
|
|
532
|
+
method: 'POST',
|
|
533
|
+
headers: {
|
|
534
|
+
'Authorization': 'Bearer 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',
|
|
535
|
+
'Content-Type': 'application/json'
|
|
536
|
+
},
|
|
537
|
+
body: JSON.stringify({ inputs: formattedMessages })
|
|
538
|
+
});
|
|
522
539
|
|
|
523
|
-
|
|
540
|
+
if (!response.ok) {
|
|
541
|
+
throw new Error('Network response was not ok');
|
|
542
|
+
}
|
|
524
543
|
|
|
525
|
-
|
|
544
|
+
const responseData = await response.json();
|
|
545
|
+
const generatedText = responseData[0].generated_text;
|
|
546
|
+
const lines = generatedText.split('\n').slice(1);
|
|
547
|
+
const output = lines.join('\n');
|
|
526
548
|
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
console.error('Error:', error.
|
|
530
|
-
return 'Please wait i am on cooldown.'
|
|
531
|
-
|
|
549
|
+
return output;
|
|
550
|
+
} catch (error: any) {
|
|
551
|
+
console.error('Error:', error.message);
|
|
552
|
+
return 'Please wait i am on cooldown.';
|
|
553
|
+
}
|
|
532
554
|
}
|
|
533
555
|
|
|
534
556
|
export async function starChat(prompt: string) {
|
|
535
|
-
const messages = [{"role":"user","content": `${prompt}`}]
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
557
|
+
const messages = [{"role":"user","content": `${prompt}`}];
|
|
558
|
+
|
|
559
|
+
try {
|
|
560
|
+
const response = await fetch('https://api-inference.huggingface.co/models/HuggingFaceH4/starchat2-15b-v0.1', {
|
|
561
|
+
method: 'POST',
|
|
562
|
+
headers: {
|
|
563
|
+
'Authorization': 'Bearer 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',
|
|
564
|
+
'Content-Type': 'application/json'
|
|
565
|
+
},
|
|
566
|
+
body: JSON.stringify({ inputs: messages })
|
|
567
|
+
});
|
|
545
568
|
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
const chatbotResponseString = chatbotResponseArray.join(' ');
|
|
569
|
+
if (!response.ok) {
|
|
570
|
+
throw new Error('Network response was not ok');
|
|
571
|
+
}
|
|
550
572
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
573
|
+
const responseData = await response.json();
|
|
574
|
+
const chatbotReply = responseData[0];
|
|
575
|
+
const chatbotResponseText = chatbotReply.generated_text.replace(/^.*?\n.*?\n/, '');
|
|
576
|
+
const chatbotResponseArray = JSON.parse(chatbotResponseText);
|
|
577
|
+
const chatbotResponseString = chatbotResponseArray.join(' ');
|
|
578
|
+
|
|
579
|
+
return chatbotResponseString;
|
|
580
|
+
} catch (error: any) {
|
|
581
|
+
console.error('Error:', error.message);
|
|
582
|
+
return null;
|
|
583
|
+
}
|
|
556
584
|
}
|
|
557
585
|
|
|
558
586
|
export async function zephyr_beta(prompt: string) {
|
|
587
|
+
const messages = [{"role":"user","content": `${prompt}` }];
|
|
588
|
+
|
|
589
|
+
try {
|
|
590
|
+
const response = await fetch('https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta', {
|
|
591
|
+
method: 'POST',
|
|
592
|
+
headers: {
|
|
593
|
+
'Authorization': 'Bearer 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',
|
|
594
|
+
'Content-Type': 'application/json'
|
|
595
|
+
},
|
|
596
|
+
body: JSON.stringify({ inputs: messages })
|
|
597
|
+
});
|
|
559
598
|
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
inputs: JSON.stringify(messages),
|
|
564
|
-
}, {
|
|
565
|
-
headers: {
|
|
566
|
-
'Authorization': `Bearer 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`,
|
|
567
|
-
},
|
|
568
|
-
});
|
|
569
|
-
|
|
570
|
-
const chatbotReply = response.data[0];
|
|
571
|
-
|
|
572
|
-
const textParts = chatbotReply.generated_text.split('\n');
|
|
573
|
-
|
|
574
|
-
const secondArrayString = textParts[2];
|
|
575
|
-
const chatbotResponseArray = JSON.parse(secondArrayString);
|
|
576
|
-
|
|
577
|
-
const chatbotResponseString = chatbotResponseArray.map((obj: any) => obj.content).join(' ');
|
|
599
|
+
if (!response.ok) {
|
|
600
|
+
throw new Error('Network response was not ok');
|
|
601
|
+
}
|
|
578
602
|
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
603
|
+
const responseData = await response.json();
|
|
604
|
+
const chatbotReply = responseData[0];
|
|
605
|
+
const textParts = chatbotReply.generated_text.split('\n');
|
|
606
|
+
const secondArrayString = textParts[2];
|
|
607
|
+
const chatbotResponseArray = JSON.parse(secondArrayString);
|
|
608
|
+
const chatbotResponseString = chatbotResponseArray.map((obj: any) => obj.content).join(' ');
|
|
609
|
+
|
|
610
|
+
return chatbotResponseString;
|
|
611
|
+
} catch (error: any) {
|
|
612
|
+
console.error('Error:', error.message);
|
|
613
|
+
return null;
|
|
614
|
+
}
|
|
615
|
+
}
|
package/lib/ai/functions/draw.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import translate from "@iamtraction/google-translate";
|
|
2
2
|
import sharp from "sharp";
|
|
3
3
|
import { ButtonBuilder, StringSelectMenuBuilder, StringSelectMenuOptionBuilder, ButtonStyle, ActionRowBuilder, AttachmentBuilder, AttachmentData } from "discord.js";
|
|
4
|
-
import axios from "axios";
|
|
5
4
|
import api from "api";
|
|
6
5
|
|
|
7
6
|
const sdk: any = api("@prodia/v1.3.0#be019b2kls0gqss3");
|
|
@@ -88,8 +87,8 @@ async function aiImagine(
|
|
|
88
87
|
nsfw: boolean,
|
|
89
88
|
nsfwKeyWords: string[],
|
|
90
89
|
) {
|
|
91
|
-
const maxRetryAttempts =
|
|
92
|
-
const retryInterval =
|
|
90
|
+
const maxRetryAttempts = 3;
|
|
91
|
+
const retryInterval = 10000;
|
|
93
92
|
let response: any;
|
|
94
93
|
async function retry(fn: any, retriesLeft = maxRetryAttempts) {
|
|
95
94
|
try {
|
|
@@ -98,7 +97,6 @@ async function aiImagine(
|
|
|
98
97
|
if (retriesLeft === 0) {
|
|
99
98
|
throw error;
|
|
100
99
|
}
|
|
101
|
-
|
|
102
100
|
await new Promise((resolve) => setTimeout(resolve, retryInterval));
|
|
103
101
|
return retry(fn, retriesLeft - 1);
|
|
104
102
|
}
|
|
@@ -161,38 +159,45 @@ async function aiImagine(
|
|
|
161
159
|
let buffferedImage: any;
|
|
162
160
|
|
|
163
161
|
if (imageModel === "v3") {
|
|
164
|
-
const res = await retry(() =>
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
162
|
+
const res = await retry(async () => {
|
|
163
|
+
const resp = await fetch(response.url, {
|
|
164
|
+
method: 'GET',
|
|
165
|
+
headers: {
|
|
166
|
+
'Content-Type': 'application/octet-stream'
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
if (!resp.ok) {
|
|
170
|
+
throw new Error("Failed to fetch image data.");
|
|
171
|
+
}
|
|
172
|
+
return await resp.arrayBuffer();
|
|
173
|
+
});
|
|
174
|
+
|
|
170
175
|
await message.channel?.sendTyping();
|
|
171
|
-
|
|
172
|
-
buffferedImage = Buffer.from(res
|
|
173
|
-
|
|
176
|
+
|
|
177
|
+
buffferedImage = Buffer.from(res, "binary");
|
|
178
|
+
|
|
174
179
|
const resizedImage = await sharp(buffferedImage)
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
+
.resize({
|
|
181
|
+
width: 0x320,
|
|
182
|
+
})
|
|
183
|
+
.toBuffer();
|
|
184
|
+
|
|
180
185
|
const attachment = {
|
|
181
|
-
|
|
182
|
-
|
|
186
|
+
file: resizedImage,
|
|
187
|
+
name: `image_${_0x4d7fb6 + 1}.png`,
|
|
183
188
|
} as AttachmentData;
|
|
184
|
-
|
|
189
|
+
|
|
185
190
|
attachData.push(attachment);
|
|
186
|
-
|
|
191
|
+
|
|
187
192
|
const urlButton = new ButtonBuilder()
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
193
|
+
.setStyle(ButtonStyle.Link)
|
|
194
|
+
.setLabel(`Image ${_0x4d7fb6 + 1}`)
|
|
195
|
+
.setURL(response.url);
|
|
196
|
+
|
|
192
197
|
buttonsRow1.push(urlButton);
|
|
193
|
-
|
|
198
|
+
|
|
194
199
|
imageUrls.push(response.url);
|
|
195
|
-
|
|
200
|
+
} else {
|
|
196
201
|
const imageUrl = response.url || response;
|
|
197
202
|
|
|
198
203
|
await message.channel?.sendTyping();
|
|
@@ -387,51 +392,44 @@ async function checkJobStatus(jobId: number | string | any) {
|
|
|
387
392
|
|
|
388
393
|
async function attemptImageCaptioning(imageUrl: string) {
|
|
389
394
|
try {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
}
|
|
415
|
-
console.error(`Error fetching data: ${error.message}`);
|
|
416
|
-
throw error;
|
|
417
|
-
}
|
|
418
|
-
};
|
|
395
|
+
let retryCount = 0;
|
|
396
|
+
const maxRetries = 3;
|
|
397
|
+
|
|
398
|
+
const fetchData = async () => {
|
|
399
|
+
try {
|
|
400
|
+
const response = await fetch(`https://api-inference.huggingface.co/models/Salesforce/blip-image-captioning-base`, {
|
|
401
|
+
method: 'POST',
|
|
402
|
+
headers: {
|
|
403
|
+
"Content-Type": "application/json",
|
|
404
|
+
Authorization: `Bearer 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`,
|
|
405
|
+
},
|
|
406
|
+
body: JSON.stringify({ image: imageUrl })
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
if (response.ok) {
|
|
410
|
+
return await response.json();
|
|
411
|
+
} else {
|
|
412
|
+
console.error(`Failed to fetch image captioning API: ${response.statusText}`);
|
|
413
|
+
return null;
|
|
414
|
+
}
|
|
415
|
+
} catch (error: any) {
|
|
416
|
+
console.error(`Error fetching data: ${error.message}`);
|
|
417
|
+
throw error;
|
|
418
|
+
}
|
|
419
|
+
};
|
|
419
420
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
);
|
|
427
|
-
retryCount++;
|
|
421
|
+
while (retryCount < maxRetries) {
|
|
422
|
+
try {
|
|
423
|
+
return await fetchData();
|
|
424
|
+
} catch (error: any) {
|
|
425
|
+
retryCount++;
|
|
426
|
+
}
|
|
428
427
|
}
|
|
429
|
-
}
|
|
430
428
|
|
|
431
|
-
|
|
429
|
+
return null;
|
|
432
430
|
} catch (error: any) {
|
|
433
|
-
|
|
434
|
-
|
|
431
|
+
console.error(`Error in attemptImageCaptioning: ${error.message}`);
|
|
432
|
+
return null;
|
|
435
433
|
}
|
|
436
434
|
}
|
|
437
435
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Hercai } from "hercai";
|
|
2
|
-
import translate
|
|
3
|
-
import axios from "axios";
|
|
2
|
+
import translate from "@iamtraction/google-translate";
|
|
4
3
|
import { createWorker, recognize } from "tesseract.js";
|
|
5
4
|
import { chunkString } from "./chunkString";
|
|
6
5
|
import { aiImagine } from "./draw";
|
|
@@ -8,7 +7,7 @@ import fs from "fs";
|
|
|
8
7
|
|
|
9
8
|
const herc = new Hercai();
|
|
10
9
|
let isProcessing = false;
|
|
11
|
-
type ChatModelOption = "v3" | "v3-32k" | "turbo" | "turbo-16k" | "gemini"
|
|
10
|
+
type ChatModelOption = "v3" | "v3-32k" | "turbo" | "turbo-16k" | "gemini";
|
|
12
11
|
|
|
13
12
|
async function aiVoice(
|
|
14
13
|
message: any,
|
|
@@ -68,20 +67,16 @@ async function aiVoice(
|
|
|
68
67
|
setTimeout(async () => {
|
|
69
68
|
const encodedChunk = encodeURIComponent(chunk);
|
|
70
69
|
const url = `https://translate.google.com/translate_tts?ie=UTF-8&tl=en&client=tw-ob&q=${encodedChunk}`;
|
|
71
|
-
const
|
|
72
|
-
responseType: "stream",
|
|
70
|
+
const response = await fetch(url, {
|
|
73
71
|
headers: {
|
|
74
72
|
Referer: "http://translate.google.com/",
|
|
75
73
|
"User-Agent": "stagefright/1.2 (Linux;Android 5.0)",
|
|
76
74
|
},
|
|
77
75
|
});
|
|
76
|
+
const blob = await response.blob();
|
|
77
|
+
const file = new File([blob], "respond.mp3");
|
|
78
78
|
await message.reply({
|
|
79
|
-
files: [
|
|
80
|
-
{
|
|
81
|
-
attachment: mp3Stream.data,
|
|
82
|
-
name: "respond.mp3",
|
|
83
|
-
},
|
|
84
|
-
],
|
|
79
|
+
files: [file],
|
|
85
80
|
allowedMentions: { repliedUser: false },
|
|
86
81
|
});
|
|
87
82
|
}, delay);
|
|
@@ -94,13 +89,12 @@ async function aiVoice(
|
|
|
94
89
|
|
|
95
90
|
const options = {
|
|
96
91
|
method: "POST",
|
|
97
|
-
url: "https://text-to-speech-neural-google.p.rapidapi.com/generateAudioFiles",
|
|
98
92
|
headers: {
|
|
99
93
|
"content-type": "application/json",
|
|
100
94
|
"X-RapidAPI-Key": apiKey,
|
|
101
95
|
"X-RapidAPI-Host": "text-to-speech-neural-google.p.rapidapi.com",
|
|
102
96
|
},
|
|
103
|
-
|
|
97
|
+
body: JSON.stringify({
|
|
104
98
|
audioFormat: "ogg",
|
|
105
99
|
paragraphChunks: [msg],
|
|
106
100
|
voiceParams: {
|
|
@@ -108,13 +102,13 @@ async function aiVoice(
|
|
|
108
102
|
engine: "google",
|
|
109
103
|
languageCode: "en-US",
|
|
110
104
|
},
|
|
111
|
-
},
|
|
105
|
+
}),
|
|
112
106
|
};
|
|
113
107
|
|
|
114
108
|
try {
|
|
115
|
-
const response = await
|
|
116
|
-
const audioData = response.
|
|
117
|
-
fs.writeFileSync("output.ogg", Buffer.from(audioData, "base64"));
|
|
109
|
+
const response = await fetch("https://text-to-speech-neural-google.p.rapidapi.com/generateAudioFiles", options);
|
|
110
|
+
const audioData = await response.json();
|
|
111
|
+
fs.writeFileSync("output.ogg", Buffer.from(audioData.audioStream, "base64"));
|
|
118
112
|
await message.reply({
|
|
119
113
|
files: [
|
|
120
114
|
{
|
|
@@ -142,19 +136,18 @@ async function aiVoice(
|
|
|
142
136
|
|
|
143
137
|
const options = {
|
|
144
138
|
method: "POST",
|
|
145
|
-
url: "https://cloudlabs-text-to-speech.p.rapidapi.com/synthesize",
|
|
146
139
|
headers: {
|
|
147
140
|
"content-type": "application/x-www-form-urlencoded",
|
|
148
141
|
"X-RapidAPI-Key": apiKey,
|
|
149
142
|
"X-RapidAPI-Host": "cloudlabs-text-to-speech.p.rapidapi.com",
|
|
150
143
|
},
|
|
151
|
-
|
|
144
|
+
body: encodedParams.toString(),
|
|
152
145
|
};
|
|
153
146
|
|
|
154
147
|
try {
|
|
155
|
-
const response = await
|
|
156
|
-
const
|
|
157
|
-
await message.reply(
|
|
148
|
+
const response = await fetch("https://cloudlabs-text-to-speech.p.rapidapi.com/synthesize", options);
|
|
149
|
+
const { result: { audio_url } } = await response.json();
|
|
150
|
+
await message.reply(audio_url, {
|
|
158
151
|
allowedMentions: { repliedUser: false },
|
|
159
152
|
});
|
|
160
153
|
} catch (error) {
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
|
|
3
1
|
export async function readImage(imageUrl: string) {
|
|
4
2
|
try {
|
|
5
3
|
let retryCount = 0;
|
|
@@ -7,15 +5,17 @@ export async function readImage(imageUrl: string) {
|
|
|
7
5
|
|
|
8
6
|
const fetchData = async () => {
|
|
9
7
|
try {
|
|
10
|
-
const response = await
|
|
8
|
+
const response = await fetch("https://api-inference.huggingface.co/models/Salesforce/blip-image-captioning-large", {
|
|
9
|
+
method: 'POST',
|
|
11
10
|
headers: {
|
|
12
11
|
"Content-Type": "application/json",
|
|
13
12
|
Authorization: "Bearer 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",
|
|
14
13
|
},
|
|
14
|
+
body: JSON.stringify({ image: imageUrl })
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
-
if (response.
|
|
18
|
-
return response.
|
|
17
|
+
if (response.ok) {
|
|
18
|
+
return await response.json();
|
|
19
19
|
} else {
|
|
20
20
|
return null;
|
|
21
21
|
}
|
|
@@ -27,7 +27,7 @@ export async function readImage(imageUrl: string) {
|
|
|
27
27
|
while (retryCount < maxRetries) {
|
|
28
28
|
try {
|
|
29
29
|
return await fetchData();
|
|
30
|
-
} catch (error
|
|
30
|
+
} catch (error) {
|
|
31
31
|
retryCount++;
|
|
32
32
|
console.error(`Error fetching data (Retry ${retryCount}): ${error}`);
|
|
33
33
|
}
|