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.
Files changed (131) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
  2. package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  3. package/.github/dependabot.yml +7 -0
  4. package/.tsbuildinfo +1 -1
  5. package/CODE_OF_CONDUCT.md +128 -0
  6. package/LICENSE +21 -0
  7. package/README.md +27 -21
  8. package/SECURITY.md +20 -0
  9. package/change logs.md +1 -1
  10. package/examples/barchart.txt +0 -2
  11. package/examples/linechart.txt +0 -2
  12. package/lib/ai/ApexAI.ts +116 -85
  13. package/lib/ai/functions/draw.ts +67 -69
  14. package/lib/ai/functions/generateVoiceResponse.ts +15 -22
  15. package/lib/ai/functions/readImagess.ts +6 -6
  16. package/lib/ai/functions/typeWriter.ts +0 -2
  17. package/lib/canvas/ApexPainter.ts +75 -80
  18. package/lib/canvas/utils/bg.ts +7 -4
  19. package/lib/canvas/utils/charts.ts +37 -22
  20. package/lib/canvas/utils/general functions.ts +71 -53
  21. package/lib/canvas/utils/types.ts +14 -7
  22. package/lib/index.ts +6 -6
  23. package/package.json +3 -3
  24. package/dist/ai/ApexAI.d.ts +0 -62
  25. package/dist/ai/ApexAI.d.ts.map +0 -1
  26. package/dist/ai/ApexAI.js +0 -421
  27. package/dist/ai/ApexAI.js.map +0 -1
  28. package/dist/ai/buttons/drawMenu.d.ts +0 -3
  29. package/dist/ai/buttons/drawMenu.d.ts.map +0 -1
  30. package/dist/ai/buttons/drawMenu.js +0 -274
  31. package/dist/ai/buttons/drawMenu.js.map +0 -1
  32. package/dist/ai/buttons/tools.d.ts +0 -3
  33. package/dist/ai/buttons/tools.d.ts.map +0 -1
  34. package/dist/ai/buttons/tools.js +0 -445
  35. package/dist/ai/buttons/tools.js.map +0 -1
  36. package/dist/ai/functions/aivoice.d.ts +0 -1
  37. package/dist/ai/functions/aivoice.d.ts.map +0 -1
  38. package/dist/ai/functions/aivoice.js +0 -2
  39. package/dist/ai/functions/aivoice.js.map +0 -1
  40. package/dist/ai/functions/chunkString.d.ts +0 -2
  41. package/dist/ai/functions/chunkString.d.ts.map +0 -1
  42. package/dist/ai/functions/chunkString.js +0 -8
  43. package/dist/ai/functions/chunkString.js.map +0 -1
  44. package/dist/ai/functions/draw.d.ts +0 -3
  45. package/dist/ai/functions/draw.d.ts.map +0 -1
  46. package/dist/ai/functions/draw.js +0 -387
  47. package/dist/ai/functions/draw.js.map +0 -1
  48. package/dist/ai/functions/generateVoiceResponse.d.ts +0 -3
  49. package/dist/ai/functions/generateVoiceResponse.d.ts.map +0 -1
  50. package/dist/ai/functions/generateVoiceResponse.js +0 -158
  51. package/dist/ai/functions/generateVoiceResponse.js.map +0 -1
  52. package/dist/ai/functions/imageReader.d.ts +0 -3
  53. package/dist/ai/functions/imageReader.d.ts.map +0 -1
  54. package/dist/ai/functions/imageReader.js +0 -23
  55. package/dist/ai/functions/imageReader.js.map +0 -1
  56. package/dist/ai/functions/readFiles.d.ts +0 -3
  57. package/dist/ai/functions/readFiles.d.ts.map +0 -1
  58. package/dist/ai/functions/readFiles.js +0 -62
  59. package/dist/ai/functions/readFiles.js.map +0 -1
  60. package/dist/ai/functions/readImagess.d.ts +0 -2
  61. package/dist/ai/functions/readImagess.d.ts.map +0 -1
  62. package/dist/ai/functions/readImagess.js +0 -48
  63. package/dist/ai/functions/readImagess.js.map +0 -1
  64. package/dist/ai/functions/shouldDrawImage.d.ts +0 -2
  65. package/dist/ai/functions/shouldDrawImage.d.ts.map +0 -1
  66. package/dist/ai/functions/shouldDrawImage.js +0 -12
  67. package/dist/ai/functions/shouldDrawImage.js.map +0 -1
  68. package/dist/ai/functions/typeWriter.d.ts +0 -2
  69. package/dist/ai/functions/typeWriter.d.ts.map +0 -1
  70. package/dist/ai/functions/typeWriter.js +0 -24
  71. package/dist/ai/functions/typeWriter.js.map +0 -1
  72. package/dist/ai/models.d.ts +0 -9
  73. package/dist/ai/models.d.ts.map +0 -1
  74. package/dist/ai/models.js +0 -575
  75. package/dist/ai/models.js.map +0 -1
  76. package/dist/ai/utils.d.ts +0 -11
  77. package/dist/ai/utils.d.ts.map +0 -1
  78. package/dist/ai/utils.js +0 -24
  79. package/dist/ai/utils.js.map +0 -1
  80. package/dist/canvas/ApexPainter.d.ts +0 -38
  81. package/dist/canvas/ApexPainter.d.ts.map +0 -1
  82. package/dist/canvas/ApexPainter.js +0 -439
  83. package/dist/canvas/ApexPainter.js.map +0 -1
  84. package/dist/canvas/utils/bg.d.ts +0 -23
  85. package/dist/canvas/utils/bg.d.ts.map +0 -1
  86. package/dist/canvas/utils/bg.js +0 -74
  87. package/dist/canvas/utils/bg.js.map +0 -1
  88. package/dist/canvas/utils/charts.d.ts +0 -9
  89. package/dist/canvas/utils/charts.d.ts.map +0 -1
  90. package/dist/canvas/utils/charts.js +0 -454
  91. package/dist/canvas/utils/charts.js.map +0 -1
  92. package/dist/canvas/utils/circular.d.ts +0 -10
  93. package/dist/canvas/utils/circular.d.ts.map +0 -1
  94. package/dist/canvas/utils/circular.js +0 -22
  95. package/dist/canvas/utils/circular.js.map +0 -1
  96. package/dist/canvas/utils/customLines.d.ts +0 -2
  97. package/dist/canvas/utils/customLines.d.ts.map +0 -1
  98. package/dist/canvas/utils/customLines.js +0 -50
  99. package/dist/canvas/utils/customLines.js.map +0 -1
  100. package/dist/canvas/utils/general functions.d.ts +0 -21
  101. package/dist/canvas/utils/general functions.d.ts.map +0 -1
  102. package/dist/canvas/utils/general functions.js +0 -391
  103. package/dist/canvas/utils/general functions.js.map +0 -1
  104. package/dist/canvas/utils/imageProperties.d.ts +0 -60
  105. package/dist/canvas/utils/imageProperties.d.ts.map +0 -1
  106. package/dist/canvas/utils/imageProperties.js +0 -331
  107. package/dist/canvas/utils/imageProperties.js.map +0 -1
  108. package/dist/canvas/utils/radius.d.ts +0 -10
  109. package/dist/canvas/utils/radius.d.ts.map +0 -1
  110. package/dist/canvas/utils/radius.js +0 -31
  111. package/dist/canvas/utils/radius.js.map +0 -1
  112. package/dist/canvas/utils/textProperties.d.ts +0 -18
  113. package/dist/canvas/utils/textProperties.d.ts.map +0 -1
  114. package/dist/canvas/utils/textProperties.js +0 -67
  115. package/dist/canvas/utils/textProperties.js.map +0 -1
  116. package/dist/canvas/utils/types.d.ts +0 -414
  117. package/dist/canvas/utils/types.d.ts.map +0 -1
  118. package/dist/canvas/utils/types.js +0 -5
  119. package/dist/canvas/utils/types.js.map +0 -1
  120. package/dist/canvas/utils/utils.d.ts +0 -20
  121. package/dist/canvas/utils/utils.d.ts.map +0 -1
  122. package/dist/canvas/utils/utils.js +0 -48
  123. package/dist/canvas/utils/utils.js.map +0 -1
  124. package/dist/index.d.ts +0 -11
  125. package/dist/index.d.ts.map +0 -1
  126. package/dist/index.js +0 -65
  127. package/dist/index.js.map +0 -1
  128. package/dist/utils.d.ts +0 -12
  129. package/dist/utils.d.ts.map +0 -1
  130. package/dist/utils.js +0 -12
  131. 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
@@ -5,7 +5,7 @@
5
5
  ### General Chnages
6
6
 
7
7
  - Documetation moved to [Apexify.js](http://apexify.jedi-studio.com)
8
-
8
+ - Fixed minor bugs
9
9
  ### ApexAI Changes
10
10
 
11
11
  - Added custom nsfw key words filter.
@@ -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: {
@@ -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
- try {
483
- const response = await axios.post('https://api-inference.huggingface.co/models/google/gemma-7b-it', { inputs: prompt }, {
484
- headers: { 'Authorization': `Bearer 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` }
485
- });
486
- return response.data[0].generated_text;
487
- } catch (error: any) {
488
- console.error('Error fetching response:', error.message);
489
- return null;
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
- try {
495
- const response = await axios.post('https://api-inference.huggingface.co/models/google/gemma-2b-it', { inputs: prompt }, {
496
- headers: { 'Authorization': `Bearer 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` }
497
- });
498
- return response.data[0].generated_text;
499
- } catch (error: any) {
500
- console.error('Error fetching response:', error.message);
501
- return null;
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
- try {
525
+ try {
507
526
  const messages = [
508
- {"role": "user", "content": `${prompt}`}
527
+ {"role": "user", "content": `${prompt}`}
509
528
  ];
510
- const formattedMessages = messages.map(message => `[${message.role}] ${message.content}`).join('\n');
511
-
512
- const response = await axios.post(`https://api-inference.huggingface.co/models/mistralai/Mixtral-8x7B-Instruct-v0.1`, {
513
- inputs: formattedMessages
514
- }, {
515
- headers: {
516
- 'Authorization': `Bearer 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`,
517
- 'Content-Type': 'application/json'
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
- const lines = generatedText.split('\n').slice(1);
540
+ if (!response.ok) {
541
+ throw new Error('Network response was not ok');
542
+ }
524
543
 
525
- const output = lines.join('\n');
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
- return output
528
- } catch (error: any) {
529
- console.error('Error:', error.response.data);
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
- try {
538
- const response = await axios.post('https://api-inference.huggingface.co/models/HuggingFaceH4/starchat2-15b-v0.1', {
539
- inputs: JSON.stringify(messages),
540
- }, {
541
- headers: {
542
- 'Authorization': `Bearer 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`,
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
- const chatbotReply = response.data[0];
547
- const chatbotResponseText = chatbotReply.generated_text.replace(/^.*?\n.*?\n/, '');
548
- const chatbotResponseArray = JSON.parse(chatbotResponseText);
549
- const chatbotResponseString = chatbotResponseArray.join(' ');
569
+ if (!response.ok) {
570
+ throw new Error('Network response was not ok');
571
+ }
550
572
 
551
- return chatbotResponseString;
552
- } catch (error: any) {
553
- console.error('Error fetching response:', error.message);
554
- return null;
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
- const messages = [{"role":"user","content": `${prompt}` }]
561
- try {
562
- const response = await axios.post('https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta', {
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
- return chatbotResponseString;
580
- } catch (error: any) {
581
- console.error('Error fetching response:', error.message);
582
- return null;
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
+ }
@@ -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 = 4;
92
- const retryInterval = 5000;
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
- axios.get(response.url, {
166
- responseType: "arraybuffer",
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.data, "binary");
173
-
176
+
177
+ buffferedImage = Buffer.from(res, "binary");
178
+
174
179
  const resizedImage = await sharp(buffferedImage)
175
- .resize({
176
- width: 0x320,
177
- })
178
- .toBuffer();
179
-
180
+ .resize({
181
+ width: 0x320,
182
+ })
183
+ .toBuffer();
184
+
180
185
  const attachment = {
181
- file: resizedImage,
182
- name: `image_${_0x4d7fb6 + 1}.png`,
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
- .setStyle(ButtonStyle.Link)
189
- .setLabel(`Image ${_0x4d7fb6 + 1}`)
190
- .setURL(response.url);
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
- } else {
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
- let retryCount = 0;
391
- const maxRetries = 3;
392
-
393
- const fetchData = async () => {
394
- try {
395
- const response = await axios.post(
396
- `https://api-inference.huggingface.co/models/Salesforce/blip-image-captioning-base`,
397
- { image: imageUrl },
398
- {
399
- headers: {
400
- "Content-Type": "application/json",
401
- Authorization: `Bearer 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`,
402
- },
403
- },
404
- );
405
-
406
- if (response.status === 200) {
407
- return response.data[0].generated_text;
408
- } else {
409
- console.error(
410
- `Failed to fetch image captioning API: ${response.statusText}`,
411
- );
412
- return null;
413
- }
414
- } catch (error: any) {
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
- while (retryCount < maxRetries) {
421
- try {
422
- return await fetchData();
423
- } catch (error: any) {
424
- console.error(
425
- `Error fetching data (Retry ${retryCount + 1}): ${error.message}`,
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
- return null;
429
+ return null;
432
430
  } catch (error: any) {
433
- console.error(`Error in attemptImageCaptioning: ${error.message}`);
434
- return null;
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 from "@iamtraction/google-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 mp3Stream = await axios.get(url, {
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
- data: {
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 axios.request(options);
116
- const audioData = response.data.audioStream;
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
- data: encodedParams,
144
+ body: encodedParams.toString(),
152
145
  };
153
146
 
154
147
  try {
155
- const response = await axios.request(options);
156
- const audioUrl = response.data.result.audio_url;
157
- await message.reply(audioUrl, {
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 axios.post("https://api-inference.huggingface.co/models/Salesforce/blip-image-captioning-large", { image: imageUrl }, {
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.status === 200) {
18
- return response.data[0].generated_text;
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: any) {
30
+ } catch (error) {
31
31
  retryCount++;
32
32
  console.error(`Error fetching data (Retry ${retryCount}): ${error}`);
33
33
  }
@@ -1,5 +1,3 @@
1
- "use strict";
2
-
3
1
  export async function typeWriter(channel: any, sentence: string, speed: number, delay: number): Promise<void> {
4
2
  const typingMessage = await channel.send(sentence[0]);
5
3
  let typedSentence = typingMessage.content;