apexify.js 4.0.12 → 4.1.1
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/dist/ai/ApexAI.d.ts +1 -2
- package/dist/ai/ApexAI.d.ts.map +1 -1
- package/dist/ai/ApexAI.js.map +1 -1
- package/dist/ai/ApexModules.d.ts +17 -0
- package/dist/ai/ApexModules.d.ts.map +1 -0
- package/dist/ai/ApexModules.js +704 -0
- package/dist/ai/ApexModules.js.map +1 -0
- package/dist/ai/functions/draw.d.ts +1 -2
- package/dist/ai/functions/draw.d.ts.map +1 -1
- package/dist/ai/functions/draw.js +505 -504
- package/dist/ai/functions/draw.js.map +1 -1
- package/dist/ai/functions/generateVoiceResponse.d.ts +1 -2
- package/dist/ai/functions/generateVoiceResponse.d.ts.map +1 -1
- package/dist/ai/functions/generateVoiceResponse.js.map +1 -1
- package/dist/ai/functions/shouldDrawImage.js +2 -3
- package/dist/ai/functions/shouldDrawImage.js.map +1 -1
- package/dist/ai/functions/validOptions.d.ts +3 -3
- package/dist/ai/functions/validOptions.d.ts.map +1 -1
- package/dist/ai/functions/validOptions.js +44 -117
- package/dist/ai/functions/validOptions.js.map +1 -1
- package/dist/ai/modals-chat/Gemini-flash.js +2 -26
- package/dist/ai/modals-chat/Gemini-pro.d.ts.map +1 -1
- package/dist/ai/modals-chat/Gemini-pro.js +6 -3
- package/dist/ai/modals-chat/Gemini-pro.js.map +1 -1
- package/dist/ai/utils.d.ts +1 -1
- package/dist/ai/utils.d.ts.map +1 -1
- package/dist/ai/utils.js +3 -3
- package/dist/ai/utils.js.map +1 -1
- package/lib/ai/ApexAI.ts +1 -2
- package/lib/ai/ApexModules.ts +733 -0
- package/lib/ai/functions/draw.ts +33 -25
- package/lib/ai/functions/generateVoiceResponse.ts +1 -2
- package/lib/ai/functions/validOptions.ts +44 -194
- package/lib/ai/modals-chat/Gemini-pro.ts +18 -16
- package/lib/ai/utils.ts +1 -1
- package/package.json +9 -1
- package/dist/ai/direct-use.d.ts +0 -9
- package/dist/ai/direct-use.d.ts.map +0 -1
- package/dist/ai/direct-use.js +0 -572
- package/dist/ai/direct-use.js.map +0 -1
- package/dist/ai/functions/Gemini.d.ts +0 -6
- package/dist/ai/functions/Gemini.d.ts.map +0 -1
- package/dist/ai/functions/Gemini.js +0 -103
- package/dist/ai/functions/Gemini.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/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/lib/ai/direct-use.ts +0 -586
package/lib/ai/direct-use.ts
DELETED
|
@@ -1,586 +0,0 @@
|
|
|
1
|
-
import { Hercai } from 'hercai';
|
|
2
|
-
import axios from 'axios';
|
|
3
|
-
import api from "api";
|
|
4
|
-
const sdk = api("@prodia/v1.3.0#be019b2kls0gqss3");
|
|
5
|
-
sdk.auth("43435e1c-cab1-493f-a224-f51e4b97ce8d");
|
|
6
|
-
const hercai = new Hercai('6eZZOdDwm6Epdzn8mnhcX9SBDkxvoNYcNj9ILS0P44=');
|
|
7
|
-
import { apexai, starChat, facebook_ai, yi_34b } from './modals-chat/modals';
|
|
8
|
-
interface ApexImagineOptions {
|
|
9
|
-
negative?: string;
|
|
10
|
-
number?: number;
|
|
11
|
-
nsfw?: boolean;
|
|
12
|
-
}
|
|
13
|
-
type ChatModelOption = "v3" | "v3-32k" | "turbo" | "turbo-16k" | "gemini" ;
|
|
14
|
-
type ImagineModelOption = "v1" | "v2" | "v2-beta" | "lexica" | "prodia" | "animefy" | "raava" | "shonin" | "v3" | "simurg";
|
|
15
|
-
|
|
16
|
-
async function ApexImagine(model: string, prompt: string, options: ApexImagineOptions): Promise<any> {
|
|
17
|
-
try {
|
|
18
|
-
const { negative = '', number, nsfw } = options;
|
|
19
|
-
let neg = '';
|
|
20
|
-
let count = 1;
|
|
21
|
-
|
|
22
|
-
if (prompt.length >= 2000) {
|
|
23
|
-
throw new Error('Prompt can\t be longer than 2000 characters');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (negative) {
|
|
27
|
-
neg = `${negative}`;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (number && Number.isInteger(number) && number >= 1 && number <= 4) {
|
|
31
|
-
count = number;
|
|
32
|
-
} else {
|
|
33
|
-
throw new Error('Invalid number parameter. It must be an integer between 1 and 4.');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
let resultUrls: string[] = [];
|
|
37
|
-
|
|
38
|
-
const allowedModelsH = ['v1', 'v2', 'v2-beta', 'lexica', 'prodia', 'animefy', 'raava', 'shonin'];
|
|
39
|
-
const validProdiaModalsP = [
|
|
40
|
-
"3Guofeng3_v34.safetensors [50f420de]",
|
|
41
|
-
"absolutereality_V16.safetensors [37db0fc3]",
|
|
42
|
-
"absolutereality_v181.safetensors [3d9d4d2b]",
|
|
43
|
-
"amIReal_V41.safetensors [0a8a2e61]",
|
|
44
|
-
"analog-diffusion-1.0.ckpt [9ca13f02]",
|
|
45
|
-
"anythingv3_0-pruned.ckpt [2700c435]",
|
|
46
|
-
"anything-v4.5-pruned.ckpt [65745d25]",
|
|
47
|
-
"anythingV5_PrtRE.safetensors [893e49b9]",
|
|
48
|
-
"AOM3A3_orangemixs.safetensors [9600da17]",
|
|
49
|
-
"blazing_drive_v10g.safetensors [ca1c1eab]",
|
|
50
|
-
"cetusMix_Version35.safetensors [de2f2560]",
|
|
51
|
-
"childrensStories_v13D.safetensors [9dfaabcb]",
|
|
52
|
-
"childrensStories_v1SemiReal.safetensors [a1c56dbb]",
|
|
53
|
-
"childrensStories_v1ToonAnime.safetensors [2ec7b88b]",
|
|
54
|
-
"Counterfeit_v30.safetensors [9e2a8f19]",
|
|
55
|
-
"cuteyukimixAdorable_midchapter3.safetensors [04bdffe6]",
|
|
56
|
-
"cyberrealistic_v33.safetensors [82b0d085]",
|
|
57
|
-
"dalcefo_v4.safetensors [425952fe]",
|
|
58
|
-
"deliberate_v2.safetensors [10ec4b29]",
|
|
59
|
-
"deliberate_v3.safetensors [afd9d2d4]",
|
|
60
|
-
"dreamlike-anime-1.0.safetensors [4520e090]",
|
|
61
|
-
"dreamlike-diffusion-1.0.safetensors [5c9fd6e0]",
|
|
62
|
-
"dreamlike-photoreal-2.0.safetensors [fdcf65e7]",
|
|
63
|
-
"dreamshaper_6BakedVae.safetensors [114c8abb]",
|
|
64
|
-
"dreamshaper_7.safetensors [5cf5ae06]",
|
|
65
|
-
"dreamshaper_8.safetensors [9d40847d]",
|
|
66
|
-
"edgeOfRealism_eorV20.safetensors [3ed5de15]",
|
|
67
|
-
"EimisAnimeDiffusion_V1.ckpt [4f828a15]",
|
|
68
|
-
"elldreths-vivid-mix.safetensors [342d9d26]",
|
|
69
|
-
"epicrealism_naturalSinRC1VAE.safetensors [90a4c676]",
|
|
70
|
-
"ICantBelieveItsNotPhotography_seco.safetensors [4e7a3dfd]",
|
|
71
|
-
"juggernaut_aftermath.safetensors [5e20c455]",
|
|
72
|
-
"lofi_v4.safetensors [ccc204d6]",
|
|
73
|
-
"lyriel_v16.safetensors [68fceea2]",
|
|
74
|
-
"majicmixRealistic_v4.safetensors [29d0de58]",
|
|
75
|
-
"mechamix_v10.safetensors [ee685731]",
|
|
76
|
-
"meinamix_meinaV9.safetensors [2ec66ab0]",
|
|
77
|
-
"meinamix_meinaV11.safetensors [b56ce717]",
|
|
78
|
-
"neverendingDream_v122.safetensors [f964ceeb]",
|
|
79
|
-
"openjourney_V4.ckpt [ca2f377f]",
|
|
80
|
-
"pastelMixStylizedAnime_pruned_fp16.safetensors [793a26e8]",
|
|
81
|
-
"portraitplus_V1.0.safetensors [1400e684]",
|
|
82
|
-
"protogenx34.safetensors [5896f8d5]",
|
|
83
|
-
"Realistic_Vision_V1.4-pruned-fp16.safetensors [8d21810b]",
|
|
84
|
-
"Realistic_Vision_V2.0.safetensors [79587710]",
|
|
85
|
-
"Realistic_Vision_V4.0.safetensors [29a7afaa]",
|
|
86
|
-
"Realistic_Vision_V5.0.safetensors [614d1063]",
|
|
87
|
-
"redshift_diffusion-V10.safetensors [1400e684]",
|
|
88
|
-
"revAnimated_v122.safetensors [3f4fefd9]",
|
|
89
|
-
"rundiffusionFX25D_v10.safetensors [cd12b0ee]",
|
|
90
|
-
"rundiffusionFX_v10.safetensors [cd4e694d]",
|
|
91
|
-
"sdv1_4.ckpt [7460a6fa]",
|
|
92
|
-
"v1-5-pruned-emaonly.safetensors [d7049739]",
|
|
93
|
-
"v1-5-inpainting.safetensors [21c7ab71]",
|
|
94
|
-
"shoninsBeautiful_v10.safetensors [25d8c546]",
|
|
95
|
-
"theallys-mix-ii-churned.safetensors [5d9225a4]",
|
|
96
|
-
"timeless-1.0.ckpt [7c4971d4]",
|
|
97
|
-
"toonyou_beta6.safetensors [980f6b15]",
|
|
98
|
-
];
|
|
99
|
-
|
|
100
|
-
if (allowedModelsH.includes(model)) {
|
|
101
|
-
for (let i = 0; i < count; i++) {
|
|
102
|
-
try {
|
|
103
|
-
const result = await hercai.drawImage({ model: model as ImagineModelOption, prompt: prompt, negative_prompt: neg });
|
|
104
|
-
resultUrls.push(result.url);
|
|
105
|
-
} catch (error) {
|
|
106
|
-
console.error("Failed to draw image with Hercai. Retrying...", error);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
} else if (validProdiaModalsP.includes(model)) {
|
|
110
|
-
for (let i = 0; i < count; i++) {
|
|
111
|
-
const generateResponse = await sdk.generate({
|
|
112
|
-
model: model,
|
|
113
|
-
prompt: prompt,
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
const generatedJobId = generateResponse.data.job;
|
|
117
|
-
const result = await checkJobStatus(generatedJobId);
|
|
118
|
-
|
|
119
|
-
if (result) {
|
|
120
|
-
resultUrls.push(result);
|
|
121
|
-
} else {
|
|
122
|
-
console.error('Invalid result format. Expected a URL.');
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (nsfw) {
|
|
128
|
-
const checkedURLs = await apexChecker(resultUrls)
|
|
129
|
-
const nsfwWords = [
|
|
130
|
-
"porn",
|
|
131
|
-
"sex",
|
|
132
|
-
"nude",
|
|
133
|
-
"nsfw",
|
|
134
|
-
"xxx",
|
|
135
|
-
"adult",
|
|
136
|
-
"vagina",
|
|
137
|
-
"penis",
|
|
138
|
-
"boobs",
|
|
139
|
-
"fuck",
|
|
140
|
-
"orgasm",
|
|
141
|
-
"erotic",
|
|
142
|
-
"naughty",
|
|
143
|
-
"kinky",
|
|
144
|
-
"sensual",
|
|
145
|
-
"horny",
|
|
146
|
-
"lust",
|
|
147
|
-
"sperm",
|
|
148
|
-
"ejaculate",
|
|
149
|
-
"busty",
|
|
150
|
-
"booty",
|
|
151
|
-
"striptease",
|
|
152
|
-
"dildo",
|
|
153
|
-
"vibrator",
|
|
154
|
-
"fetish",
|
|
155
|
-
"bondage",
|
|
156
|
-
"anal",
|
|
157
|
-
"oral",
|
|
158
|
-
"blowjob",
|
|
159
|
-
"cumshot",
|
|
160
|
-
"gangbang",
|
|
161
|
-
"threesome",
|
|
162
|
-
"orgy",
|
|
163
|
-
"deepthroat",
|
|
164
|
-
"naked",
|
|
165
|
-
"undress",
|
|
166
|
-
"cum",
|
|
167
|
-
"suck",
|
|
168
|
-
"lick",
|
|
169
|
-
"spank",
|
|
170
|
-
"masturbate",
|
|
171
|
-
"clitoris",
|
|
172
|
-
"penetration",
|
|
173
|
-
"swinger",
|
|
174
|
-
"hooker",
|
|
175
|
-
"prostitute",
|
|
176
|
-
"escort",
|
|
177
|
-
"cumswap",
|
|
178
|
-
"creampie",
|
|
179
|
-
"rimjob",
|
|
180
|
-
"squirt",
|
|
181
|
-
"butt",
|
|
182
|
-
"ass",
|
|
183
|
-
"slut",
|
|
184
|
-
"whore",
|
|
185
|
-
"cumming",
|
|
186
|
-
"rimming",
|
|
187
|
-
"cunnilingus",
|
|
188
|
-
"fellatio",
|
|
189
|
-
"crotch",
|
|
190
|
-
"groin",
|
|
191
|
-
"erogenous",
|
|
192
|
-
"labia",
|
|
193
|
-
"testicles",
|
|
194
|
-
"climax",
|
|
195
|
-
"thrust",
|
|
196
|
-
"missionary",
|
|
197
|
-
"doggy",
|
|
198
|
-
"69",
|
|
199
|
-
"tits",
|
|
200
|
-
"pussy",
|
|
201
|
-
"cock",
|
|
202
|
-
"boobies",
|
|
203
|
-
"boner",
|
|
204
|
-
"cherry",
|
|
205
|
-
"virgin",
|
|
206
|
-
"cumming",
|
|
207
|
-
"anal beads",
|
|
208
|
-
"nipple",
|
|
209
|
-
"stripper",
|
|
210
|
-
"g-string",
|
|
211
|
-
"thong",
|
|
212
|
-
"fingering",
|
|
213
|
-
"handjob",
|
|
214
|
-
"voyeur",
|
|
215
|
-
"orgasmic",
|
|
216
|
-
"nudity",
|
|
217
|
-
"sexting",
|
|
218
|
-
"seduction",
|
|
219
|
-
"lustful",
|
|
220
|
-
"wet",
|
|
221
|
-
"hardcore",
|
|
222
|
-
"seduce",
|
|
223
|
-
"dirty",
|
|
224
|
-
"naughty",
|
|
225
|
-
"erotic",
|
|
226
|
-
"pleasure",
|
|
227
|
-
"aroused",
|
|
228
|
-
"intimate",
|
|
229
|
-
"eroticism",
|
|
230
|
-
"foreplay",
|
|
231
|
-
"dominate",
|
|
232
|
-
"submissive",
|
|
233
|
-
"bdsm",
|
|
234
|
-
"s&m",
|
|
235
|
-
"masochism",
|
|
236
|
-
"sadism",
|
|
237
|
-
"bukkake",
|
|
238
|
-
"gangbang",
|
|
239
|
-
"fetish",
|
|
240
|
-
"orgy",
|
|
241
|
-
"bondage",
|
|
242
|
-
"golden shower",
|
|
243
|
-
"dirty talk",
|
|
244
|
-
"pillow talk",
|
|
245
|
-
"sex slave",
|
|
246
|
-
"dirty dancing",
|
|
247
|
-
"striptease",
|
|
248
|
-
"pornographic",
|
|
249
|
-
"adult entertainment",
|
|
250
|
-
"sexual intercourse",
|
|
251
|
-
"titillating",
|
|
252
|
-
"sexy",
|
|
253
|
-
"hot",
|
|
254
|
-
"erotic",
|
|
255
|
-
"raunchy",
|
|
256
|
-
"stimulation",
|
|
257
|
-
"climax",
|
|
258
|
-
"horny",
|
|
259
|
-
"turn-on",
|
|
260
|
-
"kinky",
|
|
261
|
-
"lustful",
|
|
262
|
-
"sensual",
|
|
263
|
-
"passionate",
|
|
264
|
-
"intimate",
|
|
265
|
-
"provocative",
|
|
266
|
-
"tease",
|
|
267
|
-
"foreplay",
|
|
268
|
-
"satisfy",
|
|
269
|
-
"pleasure",
|
|
270
|
-
"erogenous",
|
|
271
|
-
"arousal",
|
|
272
|
-
"lust",
|
|
273
|
-
"desire",
|
|
274
|
-
"attraction",
|
|
275
|
-
"libido",
|
|
276
|
-
"orgasm",
|
|
277
|
-
"bedroom",
|
|
278
|
-
"undress",
|
|
279
|
-
"naked",
|
|
280
|
-
"kiss",
|
|
281
|
-
"touch",
|
|
282
|
-
"petting",
|
|
283
|
-
"cuddle",
|
|
284
|
-
"spooning",
|
|
285
|
-
"naughty",
|
|
286
|
-
"dirty",
|
|
287
|
-
"taboo",
|
|
288
|
-
"forbidden",
|
|
289
|
-
"sinful",
|
|
290
|
-
"sultry",
|
|
291
|
-
"risqué",
|
|
292
|
-
"racy",
|
|
293
|
-
"flirt",
|
|
294
|
-
"seduce",
|
|
295
|
-
"titillate",
|
|
296
|
-
"arouse",
|
|
297
|
-
"tempt",
|
|
298
|
-
"stimulate",
|
|
299
|
-
"seduction",
|
|
300
|
-
"pleasure",
|
|
301
|
-
"ecstasy",
|
|
302
|
-
"passion",
|
|
303
|
-
"intimacy",
|
|
304
|
-
"sensuality",
|
|
305
|
-
"eroticism",
|
|
306
|
-
"fetish",
|
|
307
|
-
"fantasy",
|
|
308
|
-
"kink",
|
|
309
|
-
"role-play",
|
|
310
|
-
"dominance",
|
|
311
|
-
"submission",
|
|
312
|
-
"bondage",
|
|
313
|
-
"masochism",
|
|
314
|
-
"sadism",
|
|
315
|
-
"orgy",
|
|
316
|
-
"swinging",
|
|
317
|
-
"voyeurism",
|
|
318
|
-
"exhibitionism",
|
|
319
|
-
"cunnilingus",
|
|
320
|
-
"fellatio",
|
|
321
|
-
"69",
|
|
322
|
-
"blowjob",
|
|
323
|
-
"anal",
|
|
324
|
-
"doggy style",
|
|
325
|
-
"missionary",
|
|
326
|
-
"cowgirl",
|
|
327
|
-
"reverse cowgirl",
|
|
328
|
-
"threesome",
|
|
329
|
-
"foursome",
|
|
330
|
-
"gangbang",
|
|
331
|
-
"rimming",
|
|
332
|
-
"golden shower",
|
|
333
|
-
"facial",
|
|
334
|
-
"creampie",
|
|
335
|
-
"cumshot",
|
|
336
|
-
"squirting",
|
|
337
|
-
"masturbation",
|
|
338
|
-
"orgasm",
|
|
339
|
-
"erect",
|
|
340
|
-
"nipple",
|
|
341
|
-
"pubic",
|
|
342
|
-
"erection",
|
|
343
|
-
"ejaculation",
|
|
344
|
-
"clitoris",
|
|
345
|
-
"penetration",
|
|
346
|
-
"vibrator",
|
|
347
|
-
"dildo",
|
|
348
|
-
"strap-on",
|
|
349
|
-
"butt plug",
|
|
350
|
-
"anal beads",
|
|
351
|
-
"crotchless",
|
|
352
|
-
"lingerie",
|
|
353
|
-
"corset",
|
|
354
|
-
"stockings",
|
|
355
|
-
"garter",
|
|
356
|
-
"bra",
|
|
357
|
-
"panties",
|
|
358
|
-
"thong",
|
|
359
|
-
"G-string",
|
|
360
|
-
"bikini",
|
|
361
|
-
"lingerie",
|
|
362
|
-
"boudoir",
|
|
363
|
-
"stripper",
|
|
364
|
-
"exotic dancer",
|
|
365
|
-
"burlesque",
|
|
366
|
-
"pole dance",
|
|
367
|
-
"erotic dance",
|
|
368
|
-
"nude",
|
|
369
|
-
"topless",
|
|
370
|
-
"lap dance",
|
|
371
|
-
"strip tease",
|
|
372
|
-
"private dance",
|
|
373
|
-
"camgirl",
|
|
374
|
-
"porn star",
|
|
375
|
-
"sex worker",
|
|
376
|
-
"escort",
|
|
377
|
-
"prostitute",
|
|
378
|
-
"whore",
|
|
379
|
-
"call girl",
|
|
380
|
-
"hooker",
|
|
381
|
-
"streetwalker",
|
|
382
|
-
"courtesan",
|
|
383
|
-
"madam",
|
|
384
|
-
"mistress",
|
|
385
|
-
"dominatrix",
|
|
386
|
-
"submissive",
|
|
387
|
-
"slave",
|
|
388
|
-
"master",
|
|
389
|
-
"mistress",
|
|
390
|
-
"sir",
|
|
391
|
-
"madame",
|
|
392
|
-
"domina",
|
|
393
|
-
"domme",
|
|
394
|
-
"sissy",
|
|
395
|
-
"bottom",
|
|
396
|
-
"top",
|
|
397
|
-
"fetish",
|
|
398
|
-
"kink",
|
|
399
|
-
"leather",
|
|
400
|
-
"latex",
|
|
401
|
-
"rubber",
|
|
402
|
-
"bondage",
|
|
403
|
-
"rope",
|
|
404
|
-
"chain",
|
|
405
|
-
"spanking",
|
|
406
|
-
"whipping",
|
|
407
|
-
"caning",
|
|
408
|
-
"flogging",
|
|
409
|
-
"paddling",
|
|
410
|
-
"torture",
|
|
411
|
-
"humiliation",
|
|
412
|
-
"degradation",
|
|
413
|
-
"submission",
|
|
414
|
-
"dominance",
|
|
415
|
-
"sadism",
|
|
416
|
-
"masochism",
|
|
417
|
-
"bukkake",
|
|
418
|
-
"facial",
|
|
419
|
-
"creampie",
|
|
420
|
-
"cum swap",
|
|
421
|
-
"cum play",
|
|
422
|
-
"cum shot",
|
|
423
|
-
"gang bang",
|
|
424
|
-
"double penetration",
|
|
425
|
-
"anal sex",
|
|
426
|
-
"oral sex",
|
|
427
|
-
"rimming",
|
|
428
|
-
"fingering",
|
|
429
|
-
"gay",
|
|
430
|
-
"lesbian",
|
|
431
|
-
"niga",
|
|
432
|
-
"underage",
|
|
433
|
-
"xnxx",
|
|
434
|
-
"xxx",
|
|
435
|
-
"pornhub",
|
|
436
|
-
];
|
|
437
|
-
for (const text of checkedURLs) {
|
|
438
|
-
if (nsfwWords.some(word => text.includes(word))) {
|
|
439
|
-
return "The generated text contains NSFW content.";
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
}
|
|
444
|
-
return resultUrls;
|
|
445
|
-
} catch (e: any) {
|
|
446
|
-
if (e.response && e.response.status === 429) {
|
|
447
|
-
console.error("Too many requests. Please try again later.");
|
|
448
|
-
return `Please wait i am in a cool down for a minute`;
|
|
449
|
-
} else if (e.response && e.response.status === 500) {
|
|
450
|
-
console.error("Internal server error. Please try again later.");
|
|
451
|
-
return `Please wait i am in a cool down for a minute`;
|
|
452
|
-
} else {
|
|
453
|
-
console.error(`Please wait i am in a cool down for a minute`);
|
|
454
|
-
return `Please wait i am in a cool down for a minute`;
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
async function checkJobStatus(jobId: string, retryCount = 3): Promise<string | null> {
|
|
460
|
-
try {
|
|
461
|
-
const getJobResponse = await sdk.getJob({ jobId: jobId });
|
|
462
|
-
const jobData = getJobResponse.data;
|
|
463
|
-
|
|
464
|
-
if (jobData.status === "generating" || jobData.status === "queued") {
|
|
465
|
-
if (retryCount > 0) {
|
|
466
|
-
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
467
|
-
return checkJobStatus(jobId, retryCount - 1);
|
|
468
|
-
} else {
|
|
469
|
-
console.error("Job failed after multiple retries:", jobData);
|
|
470
|
-
return null;
|
|
471
|
-
}
|
|
472
|
-
} else if (jobData.status === "succeeded") {
|
|
473
|
-
return jobData.imageUrl;
|
|
474
|
-
} else {
|
|
475
|
-
console.error("Job failed:", jobData);
|
|
476
|
-
return null;
|
|
477
|
-
}
|
|
478
|
-
} catch (error) {
|
|
479
|
-
console.error(error);
|
|
480
|
-
return null;
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
async function ApexChat(model: string, prompt: string): Promise<string> { // Specify the return type as string
|
|
485
|
-
try {
|
|
486
|
-
if (prompt.length >= 2000) {
|
|
487
|
-
const chunks = [];
|
|
488
|
-
while (prompt.length > 0) {
|
|
489
|
-
chunks.push(prompt.substring(0, 2000));
|
|
490
|
-
prompt = prompt.substring(2000);
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
const responses = await Promise.all(chunks.map(async (chunk) => {
|
|
494
|
-
return await processChunk(model, chunk);
|
|
495
|
-
}));
|
|
496
|
-
|
|
497
|
-
return responses.join('');
|
|
498
|
-
} else {
|
|
499
|
-
return await processChunk(model, prompt);
|
|
500
|
-
}
|
|
501
|
-
} catch (error: any) {
|
|
502
|
-
console.error(error.message);
|
|
503
|
-
return '';
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
async function processChunk(model: string, prompt: string): Promise<string> {
|
|
508
|
-
let response: string;
|
|
509
|
-
|
|
510
|
-
switch (model) {
|
|
511
|
-
case 'v3':
|
|
512
|
-
case 'v3-32k':
|
|
513
|
-
case 'turbo':
|
|
514
|
-
case 'turbo-16k':
|
|
515
|
-
case 'gemini':
|
|
516
|
-
response = (await hercai.question({ model: model as ChatModelOption, content: prompt })).reply;
|
|
517
|
-
break;
|
|
518
|
-
case 'apexChat':
|
|
519
|
-
response = await apexai(prompt);
|
|
520
|
-
break;
|
|
521
|
-
case 'starChat':
|
|
522
|
-
response = await starChat(prompt);
|
|
523
|
-
break;
|
|
524
|
-
case 'facebook-ai':
|
|
525
|
-
response = await facebook_ai(prompt);
|
|
526
|
-
break;
|
|
527
|
-
case 'yi-ai':
|
|
528
|
-
response = await yi_34b(prompt);
|
|
529
|
-
break;
|
|
530
|
-
default:
|
|
531
|
-
throw new Error('Invalid model.');
|
|
532
|
-
}
|
|
533
|
-
return response;
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
async function apexChecker(urls: any) {
|
|
537
|
-
try {
|
|
538
|
-
let retryCount = 0;
|
|
539
|
-
const maxRetries = 3;
|
|
540
|
-
|
|
541
|
-
const fetchData = async () => {
|
|
542
|
-
try {
|
|
543
|
-
const response = await axios.post(
|
|
544
|
-
`https://api-inference.huggingface.co/models/Salesforce/blip-image-captioning-base`,
|
|
545
|
-
{ image: urls },
|
|
546
|
-
{
|
|
547
|
-
headers: {
|
|
548
|
-
"Content-Type": "application/json",
|
|
549
|
-
Authorization: `Bearer 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`,
|
|
550
|
-
},
|
|
551
|
-
},
|
|
552
|
-
);
|
|
553
|
-
|
|
554
|
-
if (response.status === 200) {
|
|
555
|
-
return response.data[0].generated_text;
|
|
556
|
-
} else {
|
|
557
|
-
console.error(
|
|
558
|
-
`Failed to fetch image captioning API: ${response.statusText}`,
|
|
559
|
-
);
|
|
560
|
-
return null;
|
|
561
|
-
}
|
|
562
|
-
} catch (e: any) {
|
|
563
|
-
console.error(`Error fetching data: ${e.message}`);
|
|
564
|
-
throw e;
|
|
565
|
-
}
|
|
566
|
-
};
|
|
567
|
-
|
|
568
|
-
while (retryCount < maxRetries) {
|
|
569
|
-
try {
|
|
570
|
-
return await fetchData();
|
|
571
|
-
} catch (e: any) {
|
|
572
|
-
console.error(
|
|
573
|
-
`Error fetching data (Retry ${retryCount + 1}): ${e.message}`,
|
|
574
|
-
);
|
|
575
|
-
retryCount++;
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
return null;
|
|
580
|
-
} catch (e: any) {
|
|
581
|
-
console.error(`Error in attemptImageCaptioning: ${e.message}`);
|
|
582
|
-
return null;
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
export { ApexImagine, ApexChat };
|