apexify.js 4.0.11 → 4.1.0

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 (37) hide show
  1. package/dist/ai/ApexAI.d.ts +1 -2
  2. package/dist/ai/ApexAI.d.ts.map +1 -1
  3. package/dist/ai/ApexAI.js.map +1 -1
  4. package/dist/ai/ApexModules.d.ts +17 -0
  5. package/dist/ai/ApexModules.d.ts.map +1 -0
  6. package/dist/ai/ApexModules.js +704 -0
  7. package/dist/ai/ApexModules.js.map +1 -0
  8. package/dist/ai/functions/draw.d.ts +1 -2
  9. package/dist/ai/functions/draw.d.ts.map +1 -1
  10. package/dist/ai/functions/draw.js +504 -504
  11. package/dist/ai/functions/draw.js.map +1 -1
  12. package/dist/ai/functions/generateVoiceResponse.d.ts +1 -2
  13. package/dist/ai/functions/generateVoiceResponse.d.ts.map +1 -1
  14. package/dist/ai/functions/generateVoiceResponse.js.map +1 -1
  15. package/dist/ai/functions/shouldDrawImage.js +2 -3
  16. package/dist/ai/functions/shouldDrawImage.js.map +1 -1
  17. package/dist/ai/functions/validOptions.d.ts +4 -4
  18. package/dist/ai/functions/validOptions.d.ts.map +1 -1
  19. package/dist/ai/functions/validOptions.js +44 -117
  20. package/dist/ai/functions/validOptions.js.map +1 -1
  21. package/dist/ai/modals-chat/Gemini-pro.d.ts.map +1 -1
  22. package/dist/ai/modals-chat/Gemini-pro.js +6 -3
  23. package/dist/ai/modals-chat/Gemini-pro.js.map +1 -1
  24. package/dist/ai/utils.d.ts +1 -1
  25. package/dist/ai/utils.d.ts.map +1 -1
  26. package/dist/ai/utils.js +3 -3
  27. package/dist/ai/utils.js.map +1 -1
  28. package/lib/ai/ApexAI.ts +1 -2
  29. package/lib/ai/ApexModules.ts +733 -0
  30. package/lib/ai/functions/draw.ts +32 -25
  31. package/lib/ai/functions/generateVoiceResponse.ts +1 -2
  32. package/lib/ai/functions/shouldDrawImage.ts +3 -3
  33. package/lib/ai/functions/validOptions.ts +44 -194
  34. package/lib/ai/modals-chat/Gemini-pro.ts +18 -16
  35. package/lib/ai/utils.ts +1 -1
  36. package/package.json +8 -1
  37. package/lib/ai/direct-use.ts +0 -586
@@ -2,7 +2,7 @@ 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
4
  import axios from "axios";
5
- import { validOptions, ImageModals } from './validOptions';
5
+ import { validOptions } from './validOptions';
6
6
  import api from "api";
7
7
 
8
8
  const sdk: any = api("@prodia/v1.3.0#be019b2kls0gqss3");
@@ -11,7 +11,7 @@ async function aiImagine(
11
11
  numOfImages: number,
12
12
  textToDraw: string,
13
13
  hercai: any,
14
- imageModel: ImageModals,
14
+ imageModal: string,
15
15
  nsfw: boolean,
16
16
  nsfwKeyWords: string[],
17
17
  deepCheck: boolean,
@@ -19,10 +19,14 @@ async function aiImagine(
19
19
  buttons: any[],
20
20
  RespondMessage: any
21
21
  ) {
22
+
22
23
  const maxRetryAttempts = 4;
23
24
  const retryInterval = 5000;
24
25
  let response: any;
26
+ const imageType = await validOptions;
27
+
25
28
  async function retry(fn: any, retriesLeft = maxRetryAttempts) {
29
+
26
30
  try {
27
31
  return await fn();
28
32
  } catch (error: any) {
@@ -57,7 +61,7 @@ async function aiImagine(
57
61
 
58
62
  for (let _0x4d7fb6 = 0x0; _0x4d7fb6 < numOfImages; _0x4d7fb6++) {
59
63
  try {
60
- if (imageModel === 'prodia') {
64
+ if (imageModal === 'prodia') {
61
65
  response = await retry(() =>
62
66
  hercai.betaDrawImage({
63
67
  prompt: translatedText.text,
@@ -70,16 +74,16 @@ async function aiImagine(
70
74
  scale: enhancer.cfgScale,
71
75
  }),
72
76
  );
73
- } else if (validOptions.validHercaiModals.includes(imageModel)) {
77
+ } else if (imageType.validHercaiModals.includes(imageModal)) {
74
78
  response = await retry(() =>
75
79
  hercai.drawImage({
76
- model: imageModel,
80
+ model: imageModal,
77
81
  prompt: translatedText.text,
78
82
  }),
79
83
  );
80
- } else if (validOptions.validProdiaModals.includes(imageModel)) {
84
+ } else if (imageType.validProdiaModals.includes(imageModal)) {
81
85
  const generateResponse = await sdk.generate({
82
- model: imageModel,
86
+ model: imageModal,
83
87
  prompt: translatedText.text,
84
88
  negative_prompt: enhancer.negative_prompt,
85
89
  style_preset: enhancer.imgStyle,
@@ -95,10 +99,10 @@ async function aiImagine(
95
99
 
96
100
  const generatedJobId = generateResponse.data.job;
97
101
  response = await checkJobStatus(generatedJobId);
98
- } else if (validOptions.validSXDL.includes(imageModel)) {
102
+ } else if (imageType.validSXDL.includes(imageModal)) {
99
103
 
100
104
  const generateResponse = await sdk.sdxlGenerate({
101
- model: imageModel,
105
+ model: imageModal,
102
106
  prompt: translatedText.text,
103
107
  negative_prompt: enhancer.negative_prompt,
104
108
  style_preset: enhancer.imgStyle,
@@ -106,6 +110,8 @@ async function aiImagine(
106
110
  sampler: enhancer.sampler,
107
111
  seed: enhancer.seed,
108
112
  steps: enhancer.steps,
113
+ width: enhancer.width,
114
+ height: enhancer.height
109
115
  });
110
116
 
111
117
  await message.channel?.sendTyping();
@@ -129,7 +135,7 @@ async function aiImagine(
129
135
  }
130
136
  let buffferedImage: any;
131
137
 
132
- if (imageModel === "v3") {
138
+ if (imageModal === "v3") {
133
139
  const res = await retry(() =>
134
140
  axios.get(response.url, {
135
141
  responseType: "arraybuffer",
@@ -166,9 +172,6 @@ async function aiImagine(
166
172
 
167
173
  await message.channel?.sendTyping();
168
174
 
169
- if (nsfw) {
170
- const textToCheck = await attemptImageCaptioning(imageUrl);
171
-
172
175
  const nsfwWords: string[] = [
173
176
  "2g1c",
174
177
  "2 girls 1 cup",
@@ -652,26 +655,30 @@ async function aiImagine(
652
655
  "ass",
653
656
  ];
654
657
 
655
- if (nsfwKeyWords.length > 0) {
656
- if (textToCheck && nsfwKeyWords.some(word => textToCheck?.includes(word))) {
657
- return message.reply("Warning ⚠️. The generated image contatining nsfw content. Turn off nsfw to send nsfw images.");
658
- }
659
- }
658
+
660
659
 
661
660
  if (deepCheck) {
662
661
  if (translatedText.text && nsfwWords.some(word => translatedText.text?.includes(word))) {
663
662
  return message.reply("Warning ⚠️. Your prompt contains **`NSFW/Illegal/Prohibited`** words. Please refrain from doing this.");
664
663
  }
664
+ }
665
+
666
+ if (nsfw) {
667
+ const textToCheck = await attemptImageCaptioning(imageUrl);
665
668
 
666
- if (translatedText.text && nsfwKeyWords.some(word => translatedText.text?.includes(word))) {
669
+ if (textToCheck && nsfwWords.some(word => textToCheck.includes(word))) {
667
670
  return message.reply("Warning ⚠️. Your prompt contains **`NSFW/Illegal/Prohibited`** words. Please refrain from doing this.");
668
671
  }
669
- }
670
-
671
- if (textToCheck && nsfwWords.some(word => textToCheck?.includes(word))) {
672
- return message.reply("Warning ⚠️. The generated image contatining nsfw content. Turn off nsfw to send nsfw images.");
673
- }
672
+
673
+ if (nsfwKeyWords.length > 0) {
674
+
675
+ if (textToCheck && nsfwKeyWords.some(word => textToCheck.includes(word))) {
676
+ return message.reply("Warning ⚠️. The generated image contatining nsfw content. Turn off nsfw to send nsfw images.");
677
+ }
678
+
674
679
  }
680
+ }
681
+
675
682
 
676
683
  const attach = new AttachmentBuilder(
677
684
  imageUrl,
@@ -730,7 +737,7 @@ async function aiImagine(
730
737
  for (const imageUrl of imageUrls) {
731
738
  try {
732
739
 
733
- if (!validOptions.validEnhancers?.includes(enhancer.enhanceModal)) {
740
+ if (!imageType.validEnhancers?.includes(enhancer.enhanceModal)) {
734
741
  return await message.reply({ content: `Invalid enhancer modal (~~${enhancer.enhanceModal}~~). Please check documentation online at apexifyjs.jedi-studio.com.`})
735
742
  }
736
743
 
@@ -4,7 +4,6 @@ import axios from "axios";
4
4
  import { createWorker, recognize } from "tesseract.js";
5
5
  import { chunkString } from "./chunkString";
6
6
  import { aiImagine } from "./draw";
7
- import { ImageModals } from './validOptions';
8
7
  import fs from "fs";
9
8
 
10
9
  const hercai = new Hercai('6eZZOdDwm6Epdzn8mnhcX9SBDkxvoNYcNj9ILS0P44=');
@@ -17,7 +16,7 @@ async function aiVoice(
17
16
  finalText: string,
18
17
  hercai: any,
19
18
  drawValid: any,
20
- imageModal: ImageModals,
19
+ imageModal: string,
21
20
  chatModal: ChatModelOption,
22
21
  voiceModal: string,
23
22
  voice_code: string,
@@ -1,7 +1,7 @@
1
1
  export function toDraw(content: string, drawTrigger?: string[]): boolean {
2
- if (!drawTrigger) {
3
- return true;
4
- }
2
+
3
+ if (!drawTrigger || !content) return false;
4
+
5
5
  const lowerContent = content.toLowerCase();
6
6
  return drawTrigger.some(trigger => lowerContent.startsWith(trigger));
7
7
  }
@@ -1,84 +1,15 @@
1
- export type ImageModals =
2
- | "animagineXLV3_v30.safetensors [75f2f05b]"
3
- | "dreamshaperXL10_alpha2.safetensors [c8afe2ef]"
4
- | "dynavisionXL_0411.safetensors [c39cc051]"
5
- | "juggernautXL_v45.safetensors [e75f5471]"
6
- | "realismEngineSDXL_v10.safetensors [af771c3f]"
7
- | "realvisxlV40.safetensors [f7fdcb51]"
8
- | "sd_xl_base_1.0.safetensors [be9edd61]"
9
- | "sd_xl_base_1.0_inpainting_0.1.safetensors [5679a81a]"
10
- | "turbovisionXL_v431.safetensors [78890989]"
11
- | "3Guofeng3_v34.safetensors [50f420de]"
12
- | "absolutereality_V16.safetensors [37db0fc3]"
13
- | "absolutereality_v181.safetensors [3d9d4d2b]"
14
- | "amIReal_V41.safetensors [0a8a2e61]"
15
- | "analog-diffusion-1.0.ckpt [9ca13f02]"
16
- | "anythingv3_0-pruned.ckpt [2700c435]"
17
- | "anything-v4.5-pruned.ckpt [65745d25]"
18
- | "anythingV5_PrtRE.safetensors [893e49b9]"
19
- | "AOM3A3_orangemixs.safetensors [9600da17]"
20
- | "blazing_drive_v10g.safetensors [ca1c1eab]"
21
- | "cetusMix_Version35.safetensors [de2f2560]"
22
- | "childrensStories_v13D.safetensors [9dfaabcb]"
23
- | "childrensStories_v1SemiReal.safetensors [a1c56dbb]"
24
- | "childrensStories_v1ToonAnime.safetensors [2ec7b88b]"
25
- | "Counterfeit_v30.safetensors [9e2a8f19]"
26
- | "cuteyukimixAdorable_midchapter3.safetensors [04bdffe6]"
27
- | "cyberrealistic_v33.safetensors [82b0d085]"
28
- | "dalcefo_v4.safetensors [425952fe]"
29
- | "deliberate_v2.safetensors [10ec4b29]"
30
- | "deliberate_v3.safetensors [afd9d2d4]"
31
- | "dreamlike-anime-1.0.safetensors [4520e090]"
32
- | "dreamlike-diffusion-1.0.safetensors [5c9fd6e0]"
33
- | "dreamlike-photoreal-2.0.safetensors [fdcf65e7]"
34
- | "dreamshaper_6BakedVae.safetensors [114c8abb]"
35
- | "dreamshaper_7.safetensors [5cf5ae06]"
36
- | "dreamshaper_8.safetensors [9d40847d]"
37
- | "edgeOfRealism_eorV20.safetensors [3ed5de15]"
38
- | "EimisAnimeDiffusion_V1.ckpt [4f828a15]"
39
- | "elldreths-vivid-mix.safetensors [342d9d26]"
40
- | "epicrealism_naturalSinRC1VAE.safetensors [90a4c676]"
41
- | "ICantBelieveItsNotPhotography_seco.safetensors [4e7a3dfd]"
42
- | "juggernaut_aftermath.safetensors [5e20c455]"
43
- | "lofi_v4.safetensors [ccc204d6]"
44
- | "lyriel_v16.safetensors [68fceea2]"
45
- | "majicmixRealistic_v4.safetensors [29d0de58]"
46
- | "mechamix_v10.safetensors [ee685731]"
47
- | "meinamix_meinaV9.safetensors [2ec66ab0]"
48
- | "meinamix_meinaV11.safetensors [b56ce717]"
49
- | "neverendingDream_v122.safetensors [f964ceeb]"
50
- | "openjourney_V4.ckpt [ca2f377f]"
51
- | "pastelMixStylizedAnime_pruned_fp16.safetensors [793a26e8]"
52
- | "portraitplus_V1.0.safetensors [1400e684]"
53
- | "protogenx34.safetensors [5896f8d5]"
54
- | "Realistic_Vision_V1.4-pruned-fp16.safetensors [8d21810b]"
55
- | "Realistic_Vision_V2.0.safetensors [79587710]"
56
- | "Realistic_Vision_V4.0.safetensors [29a7afaa]"
57
- | "Realistic_Vision_V5.0.safetensors [614d1063]"
58
- | "redshift_diffusion-V10.safetensors [1400e684]"
59
- | "revAnimated_v122.safetensors [3f4fefd9]"
60
- | "rundiffusionFX25D_v10.safetensors [cd12b0ee]"
61
- | "rundiffusionFX_v10.safetensors [cd4e694d]"
62
- | "sdv1_4.ckpt [7460a6fa]"
63
- | "v1-5-pruned-emaonly.safetensors [d7049739]"
64
- | "v1-5-inpainting.safetensors [21c7ab71]"
65
- | "shoninsBeautiful_v10.safetensors [25d8c546]"
66
- | "theallys-mix-ii-churned.safetensors [5d9225a4]"
67
- | "timeless-1.0.ckpt [7c4971d4]"
68
- | "toonyou_beta6.safetensors [980f6b15]"
69
- | "v1"
70
- | "v2"
71
- | "v2-beta"
72
- | "v3"
73
- | "lexica"
74
- | "prodia"
75
- | "animefy"
76
- | "raava"
77
- | "shonin";
1
+ import api from "api";
78
2
 
79
- export const validOptions = {
3
+ const sdk = api("@prodia/v1.3.0#be019b2kls0gqss3");
80
4
 
81
- validHercaiModals: [
5
+ async function initializeValidOptions() {
6
+ const [SDModals, SDXLModals, samplers] = await Promise.all([
7
+ sdModals(),
8
+ sdxlModals(),
9
+ sampler()
10
+ ]);
11
+
12
+ const HercModals = [
82
13
  "v1",
83
14
  "v2",
84
15
  "v2-beta",
@@ -88,123 +19,42 @@ export const validOptions = {
88
19
  "animefy",
89
20
  "raava",
90
21
  "shonin"
91
- ],
92
-
93
- validEnhancers: [
94
- "ESRGAN_4x", "Lanczos", "Nearest", "LDSR", "R-ESRGAN 4x+",
95
- "R-ESRGAN 4x+ Anime6B", "ScuNET GAN", "ScuNET PSNR", "SwinIR 4x"
96
- ],
22
+ ]
97
23
 
98
- validSamplers: [
99
- "DPM++ 2M Karras",
100
- "DPM++ SDE Karras",
101
- "DPM++ 2M SDE Exponential",
102
- "DPM++ 2M SDE Karras",
103
- "Euler a",
104
- "Euler",
105
- "LMS",
106
- "Heun",
107
- "DPM2",
108
- "DPM2 a",
109
- "DPM++ 2S a",
110
- "DPM++ 2M",
111
- "DPM++ SDE",
112
- "DPM++ 2M SDE",
113
- "DPM++ 2M SDE Heun",
114
- "DPM++ 2M SDE Heun Karras",
115
- "DPM++ 2M SDE Heun Exponential",
116
- "DPM++ 3M SDE",
117
- "DPM++ 3M SDE Karras",
118
- "DPM++ 3M SDE Exponential",
119
- "DPM fast",
120
- "DPM adaptive",
121
- "LMS Karras",
122
- "DPM2 Karras",
123
- "DPM2 a Karras",
124
- "DPM++ 2S a Karras",
125
- "Restart",
126
- "DDIM",
127
- "PLMS",
128
- "UniPC"
129
- ],
24
+ return {
25
+ validHercaiModals: HercModals,
26
+ validEnhancers: [
27
+ "ESRGAN_4x", "Lanczos", "Nearest", "LDSR", "R-ESRGAN 4x+",
28
+ "R-ESRGAN 4x+ Anime6B", "ScuNET GAN", "ScuNET PSNR", "SwinIR 4x"
29
+ ],
30
+ validSamplers: samplers,
31
+ validSXDL: SDXLModals,
32
+ validImgStyle: [
33
+ "3d-model", "analog-film", "anime", "cinematic", "comic-book",
34
+ "digital-art", "enhance", "isometric", "fantasy-art", "isometric",
35
+ "line-art", "low-poly", "neon-punk", "origami", "photographic",
36
+ "pixel-art", "texture", "craft-clay"
37
+ ],
38
+ validProdiaModals: SDModals,
39
+ allModals: [...SDModals, ...SDXLModals, ...HercModals]
40
+ };
41
+ }
130
42
 
131
- validSXDL: [
132
- "animagineXLV3_v30.safetensors [75f2f05b]",
133
- "dreamshaperXL10_alpha2.safetensors [c8afe2ef]",
134
- "dynavisionXL_0411.safetensors [c39cc051]",
135
- "juggernautXL_v45.safetensors [e75f5471]",
136
- "realismEngineSDXL_v10.safetensors [af771c3f]",
137
- "realvisxlV40.safetensors [f7fdcb51]",
138
- "sd_xl_base_1.0.safetensors [be9edd61]",
139
- "sd_xl_base_1.0_inpainting_0.1.safetensors [5679a81a]",
140
- "turbovisionXL_v431.safetensors [78890989]"
141
- ],
43
+ export const validOptions = initializeValidOptions();
142
44
 
143
- validImgStyle: [
144
- "3d-model", "analog-film", "anime", "cinematic", "comic-book",
145
- "digital-art", "enhance", "isometric", "fantasy-art", "isometric",
146
- "line-art", "low-poly", "neon-punk", "origami", "photographic",
147
- "pixel-art", "texture", "craft-clay"
148
- ],
45
+ async function sdModals(): Promise<string[]> {
46
+ const SDModals = await sdk.listModels();
47
+ return SDModals;
48
+ }
149
49
 
150
- validProdiaModals: [
151
- "3Guofeng3_v34.safetensors [50f420de]",
152
- "absolutereality_V16.safetensors [37db0fc3]",
153
- "absolutereality_v181.safetensors [3d9d4d2b]",
154
- "amIReal_V41.safetensors [0a8a2e61]",
155
- "analog-diffusion-1.0.ckpt [9ca13f02]",
156
- "anythingv3_0-pruned.ckpt [2700c435]",
157
- "anything-v4.5-pruned.ckpt [65745d25]",
158
- "anythingV5_PrtRE.safetensors [893e49b9]",
159
- "AOM3A3_orangemixs.safetensors [9600da17]",
160
- "blazing_drive_v10g.safetensors [ca1c1eab]",
161
- "cetusMix_Version35.safetensors [de2f2560]",
162
- "childrensStories_v13D.safetensors [9dfaabcb]",
163
- "childrensStories_v1SemiReal.safetensors [a1c56dbb]",
164
- "childrensStories_v1ToonAnime.safetensors [2ec7b88b]",
165
- "Counterfeit_v30.safetensors [9e2a8f19]",
166
- "cuteyukimixAdorable_midchapter3.safetensors [04bdffe6]",
167
- "cyberrealistic_v33.safetensors [82b0d085]",
168
- "dalcefo_v4.safetensors [425952fe]",
169
- "deliberate_v2.safetensors [10ec4b29]",
170
- "deliberate_v3.safetensors [afd9d2d4]",
171
- "dreamlike-anime-1.0.safetensors [4520e090]",
172
- "dreamlike-diffusion-1.0.safetensors [5c9fd6e0]",
173
- "dreamlike-photoreal-2.0.safetensors [fdcf65e7]",
174
- "dreamshaper_6BakedVae.safetensors [114c8abb]",
175
- "dreamshaper_7.safetensors [5cf5ae06]",
176
- "dreamshaper_8.safetensors [9d40847d]",
177
- "edgeOfRealism_eorV20.safetensors [3ed5de15]",
178
- "EimisAnimeDiffusion_V1.ckpt [4f828a15]",
179
- "elldreths-vivid-mix.safetensors [342d9d26]",
180
- "epicrealism_naturalSinRC1VAE.safetensors [90a4c676]",
181
- "ICantBelieveItsNotPhotography_seco.safetensors [4e7a3dfd]",
182
- "juggernaut_aftermath.safetensors [5e20c455]",
183
- "lofi_v4.safetensors [ccc204d6]",
184
- "lyriel_v16.safetensors [68fceea2]",
185
- "majicmixRealistic_v4.safetensors [29d0de58]",
186
- "mechamix_v10.safetensors [ee685731]",
187
- "meinamix_meinaV9.safetensors [2ec66ab0]",
188
- "meinamix_meinaV11.safetensors [b56ce717]",
189
- "neverendingDream_v122.safetensors [f964ceeb]",
190
- "openjourney_V4.ckpt [ca2f377f]",
191
- "pastelMixStylizedAnime_pruned_fp16.safetensors [793a26e8]",
192
- "portraitplus_V1.0.safetensors [1400e684]",
193
- "protogenx34.safetensors [5896f8d5]",
194
- "Realistic_Vision_V1.4-pruned-fp16.safetensors [8d21810b]",
195
- "Realistic_Vision_V2.0.safetensors [79587710]",
196
- "Realistic_Vision_V4.0.safetensors [29a7afaa]",
197
- "Realistic_Vision_V5.0.safetensors [614d1063]",
198
- "redshift_diffusion-V10.safetensors [1400e684]",
199
- "revAnimated_v122.safetensors [3f4fefd9]",
200
- "rundiffusionFX25D_v10.safetensors [cd12b0ee]",
201
- "rundiffusionFX_v10.safetensors [cd4e694d]",
202
- "sdv1_4.ckpt [7460a6fa]",
203
- "v1-5-pruned-emaonly.safetensors [d7049739]",
204
- "v1-5-inpainting.safetensors [21c7ab71]",
205
- "shoninsBeautiful_v10.safetensors [25d8c546]",
206
- "theallys-mix-ii-churned.safetensors [5d9225a4]",
207
- "timeless-1.0.ckpt [7c4971d4]",
208
- "toonyou_beta6.safetensors [980f6b15]",
209
- ]
50
+ async function sdxlModals(): Promise<string[]> {
51
+ const SDXLModals = await sdk.listSdxlModels();
52
+ return SDXLModals;
210
53
  }
54
+
55
+
56
+ async function sampler(): Promise<[]> {
57
+ const Samplers = await sdk.listSamplers();
58
+
59
+ return Samplers
60
+ }
@@ -10,9 +10,13 @@ let currentApiKeyIndex = 0;
10
10
 
11
11
  export async function geminiPro(message: { userId: string, serverName: string, serverId: string, channelName: string, attachment: any, db: boolean }, AI: { AiPersonality: string | null, userMsg: string, API_KEY: string | null }): Promise<any> {
12
12
 
13
+ let db: any;
14
+
15
+ if (message.db) {
16
+ db = new connect({ adapter: 'json', dataPath: `${message.serverId}_ChatHistory` });
17
+ }
13
18
 
14
19
  try {
15
-
16
20
  let apiKeyIndex = currentApiKeyIndex;
17
21
  let genAI: any;
18
22
  while (apiKeyIndex < config.apiKeys.length) {
@@ -29,15 +33,14 @@ export async function geminiPro(message: { userId: string, serverName: string, s
29
33
  if (apiKeyIndex === config.apiKeys.length) {
30
34
  return 'All provided API keys are invalid.';
31
35
  }
32
-
33
36
  let personalityString: string = '';
37
+
34
38
  if (AI.AiPersonality) {
35
39
  const personalityFilePath = path.join(process.cwd(), AI.AiPersonality);
36
40
  const personalityContent = fs.readFileSync(personalityFilePath, 'utf-8');
37
41
  personalityString = personalityContent.split('\n').join(' ');
38
42
  }
39
43
 
40
-
41
44
  const generationConfig = {
42
45
  maxOutputTokens: 750,
43
46
  };
@@ -61,11 +64,9 @@ export async function geminiPro(message: { userId: string, serverName: string, s
61
64
  },
62
65
  ];
63
66
 
64
- const systemInstruction = `${personalityString}\n And working on discord in serverName: ${message.serverName} at channelName: ${message.channelName} and responding to the userName:<@ ${message.userId}>`;
67
+ const systemInstruction = `${personalityString}\n And working on discord in serverName: ${message.serverName} at channelName: ${message.channelName} and responding to the userName: <@${message.userId}>`;
65
68
  const model = genAI.getGenerativeModel({ model: "gemini-1.5-pro-latest", systemInstruction, generationConfig, safetySettings });
66
69
 
67
- let historyData: any[] | undefined = undefined;
68
-
69
70
  const defaultHistory = [
70
71
  {
71
72
  role: "user",
@@ -101,13 +102,13 @@ export async function geminiPro(message: { userId: string, serverName: string, s
101
102
  },
102
103
  ];
103
104
 
104
- let db: any;
105
+ let historyData: any[] | undefined = undefined;
105
106
 
106
107
  if (message.db) {
107
108
  db = new connect({ adapter: 'json', dataPath: `${message.serverId}_ChatHistory` });
108
109
 
109
110
  const data = await db.find(`${message.userId}_chatHistory`, { userId: message.userId });
110
-
111
+
111
112
  if (!data.results?.history || data.results?.history?.length === 0) {
112
113
  await db.update(`${message.userId}_chatHistory`, { userId: message.userId }, { $set: { history: [] } }, true);
113
114
  } else {
@@ -192,12 +193,13 @@ export async function geminiPro(message: { userId: string, serverName: string, s
192
193
  }
193
194
 
194
195
  async function urlToBase64(imageURL: string) {
195
- try {
196
- const convertedBuffer = await converter(imageURL, 'png');
197
-
198
- const base64String = convertedBuffer.toString('base64');
199
- return base64String;
200
- } catch (error: any) {
201
- throw new Error(`Failed to fetch and convert the image: ${error.message}`);
196
+ try {
197
+ const convertedBuffer = await converter(imageURL, 'png');
198
+
199
+ const base64String = convertedBuffer.toString('base64');
200
+ return base64String;
201
+ } catch (error: any) {
202
+ throw new Error(`Failed to fetch and convert the image: ${error.message}`);
203
+ }
202
204
  }
203
- }
205
+
package/lib/ai/utils.ts CHANGED
@@ -4,7 +4,7 @@ import { toDraw } from "./functions/shouldDrawImage";
4
4
  import { aiVoice } from "./functions/generateVoiceResponse";
5
5
  import { aiImagine } from "./functions/draw";
6
6
  import { readPdf, readTextFile } from "./functions/readFiles";
7
- import { ApexChat, ApexImagine } from "./direct-use";
7
+ import { ApexChat, ApexImagine } from "./ApexModules";
8
8
  import { typeWriter } from "./functions/typeWriter" ;
9
9
  import { readImage } from "./functions/readImagess";
10
10
  import { geminiPro } from "./modals-chat/Gemini-pro";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apexify.js",
3
- "version": "4.0.11",
3
+ "version": "4.1.0",
4
4
  "description": "Ai and Canvas library. Supports typescript and javascript",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -16,6 +16,13 @@
16
16
  ],
17
17
  "keywords": [
18
18
  "manipulation",
19
+ "gemini-pro",
20
+ "gemini",
21
+ "gemini-flash",
22
+ "bard",
23
+ "gpt-4",
24
+ "ai memory",
25
+ "chat history",
19
26
  "unlimited ai",
20
27
  "node-charts",
21
28
  "canvas-charts",