apexify.js 4.5.30 → 4.5.40
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.map +1 -1
- package/dist/ai/ApexAI.js +5 -12
- package/dist/ai/ApexAI.js.map +1 -1
- package/dist/ai/ApexModules.d.ts.map +1 -1
- package/dist/ai/ApexModules.js +26 -29
- package/dist/ai/ApexModules.js.map +1 -1
- package/dist/ai/functions/draw.d.ts.map +1 -1
- package/dist/ai/functions/draw.js +2 -10
- package/dist/ai/functions/draw.js.map +1 -1
- package/dist/ai/functions/validOptions.d.ts +6 -12
- package/dist/ai/functions/validOptions.d.ts.map +1 -1
- package/dist/ai/functions/validOptions.js +54 -32
- package/dist/ai/functions/validOptions.js.map +1 -1
- package/dist/ai/modals-chat/electronHub/chatmodels.d.ts +2 -2
- package/dist/ai/modals-chat/electronHub/chatmodels.d.ts.map +1 -1
- package/dist/ai/modals-chat/electronHub/chatmodels.js +26 -29
- package/dist/ai/modals-chat/electronHub/chatmodels.js.map +1 -1
- package/dist/ai/modals-chat/electronHub/imageModels.d.ts +1 -1
- package/dist/ai/modals-chat/electronHub/imageModels.d.ts.map +1 -1
- package/dist/ai/modals-chat/electronHub/imageModels.js +29 -24
- package/dist/ai/modals-chat/electronHub/imageModels.js.map +1 -1
- package/dist/ai/modals-chat/groq/chatgroq.d.ts.map +1 -1
- package/dist/ai/modals-chat/groq/chatgroq.js +10 -4
- package/dist/ai/modals-chat/groq/chatgroq.js.map +1 -1
- package/dist/ai/modals-chat/groq/imageAnalyzer.d.ts.map +1 -1
- package/dist/ai/modals-chat/groq/imageAnalyzer.js +0 -1
- package/dist/ai/modals-chat/groq/imageAnalyzer.js.map +1 -1
- package/dist/ai/modals-chat/groq/whisper.d.ts.map +1 -1
- package/dist/ai/modals-chat/groq/whisper.js +0 -3
- package/dist/ai/modals-chat/groq/whisper.js.map +1 -1
- package/dist/canvas/ApexPainter.d.ts +94 -7
- package/dist/canvas/ApexPainter.d.ts.map +1 -1
- package/dist/canvas/ApexPainter.js +443 -119
- package/dist/canvas/ApexPainter.js.map +1 -1
- package/dist/canvas/utils/bg.d.ts +3 -3
- package/dist/canvas/utils/bg.d.ts.map +1 -1
- package/dist/canvas/utils/bg.js +35 -15
- package/dist/canvas/utils/bg.js.map +1 -1
- package/dist/canvas/utils/customLines.d.ts +2 -1
- package/dist/canvas/utils/customLines.d.ts.map +1 -1
- package/dist/canvas/utils/customLines.js +67 -31
- package/dist/canvas/utils/customLines.js.map +1 -1
- package/dist/canvas/utils/general functions.d.ts +2 -2
- package/dist/canvas/utils/general functions.d.ts.map +1 -1
- package/dist/canvas/utils/general functions.js +52 -15
- package/dist/canvas/utils/general functions.js.map +1 -1
- package/dist/canvas/utils/types.d.ts +68 -0
- package/dist/canvas/utils/types.d.ts.map +1 -1
- package/dist/canvas/utils/types.js +2 -4
- package/dist/canvas/utils/types.js.map +1 -1
- package/dist/canvas/utils/utils.d.ts +2 -2
- package/dist/canvas/utils/utils.d.ts.map +1 -1
- package/dist/index.d.ts +4 -7
- package/dist/index.d.ts.map +1 -1
- package/examples/barchart.txt +71 -0
- package/examples/linechart.txt +93 -0
- package/examples/piechart.txt +67 -0
- package/lib/ai/ApexAI.ts +8 -11
- package/lib/ai/ApexModules.ts +42 -33
- package/lib/ai/functions/draw.ts +2 -8
- package/lib/ai/functions/validOptions.ts +83 -58
- package/lib/ai/modals-chat/electronHub/chatmodels.ts +40 -43
- package/lib/ai/modals-chat/electronHub/imageModels.ts +34 -32
- package/lib/ai/modals-chat/groq/chatgroq.ts +17 -7
- package/lib/ai/modals-chat/groq/imageAnalyzer.ts +0 -2
- package/lib/ai/modals-chat/groq/whisper.ts +0 -3
- package/lib/canvas/ApexPainter.ts +665 -262
- package/lib/canvas/utils/bg.ts +42 -16
- package/lib/canvas/utils/customLines.ts +88 -43
- package/lib/canvas/utils/general functions.ts +98 -41
- package/lib/canvas/utils/types.ts +77 -1
- package/lib/canvas/utils/utils.ts +6 -2
- package/package.json +24 -9
- package/lib/ai/modals-chat/freesedgpt/chat.ts +0 -31
- package/lib/ai/modals-chat/freesedgpt/fresedImagine.ts +0 -24
- package/lib/ai/modals-chat/rsn/rsnChat.ts +0 -74
package/lib/ai/ApexModules.ts
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
import { Hercai } from 'hercai';
|
|
2
|
-
import axios from 'axios';
|
|
3
2
|
import api from "api";
|
|
4
3
|
import translate from "@iamtraction/google-translate";
|
|
5
4
|
const sdk = api("@prodia/v1.3.0#be019b2kls0gqss3");
|
|
6
|
-
import {
|
|
5
|
+
import { validateModels } from "./functions/validOptions";
|
|
7
6
|
import { whisper } from './modals-chat/groq/whisper';
|
|
8
7
|
import { connect } from 'verse.db';
|
|
9
8
|
import { otherChatModels } from './modals-chat/others/otherModels';
|
|
10
|
-
import { rsnAPI } from './modals-chat/rsn/rsnChat';
|
|
11
9
|
import { chatGroq } from './modals-chat/groq/chatgroq';
|
|
12
10
|
import { geminiFast } from './modals-chat/gemini/geminiFast';
|
|
13
|
-
|
|
14
|
-
import { gpt4o } from './modals-chat/freesedgpt/chat';
|
|
15
11
|
import { groqAnalyzer } from './utils';
|
|
16
|
-
import { fresedImagine } from './modals-chat/freesedgpt/fresedImagine';
|
|
17
12
|
import { electronImagine } from './modals-chat/electronHub/imageModels';
|
|
18
13
|
import { electronChat } from './modals-chat/electronHub/chatmodels';
|
|
19
14
|
|
|
@@ -48,7 +43,7 @@ type hercmodals = "v3" | "lexica" | "prodia" | "animefy" | "raava" | "shonin" |
|
|
|
48
43
|
async function ApexImagine(model: string, prompt: string, options?: ApexImagineOptions): Promise<string[] | undefined> {
|
|
49
44
|
let imageURL: string | null = '';
|
|
50
45
|
let response: string[] = [];
|
|
51
|
-
const imageType = await validateModels;
|
|
46
|
+
const imageType = await validateModels();
|
|
52
47
|
const { Api_Key = 'eaebff6e-c7b2-477c-8edd-9aa91becf1e3', nsfw = false, deepCheck = false, nsfwWords = [], count = 2, negative_prompt = "", sampler = "DPM++ 2M Karras", height = 512, width = 512, cfg_scale = 9, steps = 20, seed = -1, image_style = "cinematic" } = options ?? {};
|
|
53
48
|
|
|
54
49
|
const translatedText = await translate(prompt, {
|
|
@@ -113,17 +108,10 @@ async function ApexImagine(model: string, prompt: string, options?: ApexImagineO
|
|
|
113
108
|
|
|
114
109
|
const generatedJobId = generating.data.job;
|
|
115
110
|
imageURL = await checkJobStatus(generatedJobId);
|
|
116
|
-
} else if (imageType.
|
|
117
|
-
const gen = await fresedImagine(translatedText.text, model, Api_Key as string);
|
|
118
|
-
if (gen === null) throw new Error('this model reached rate limit. Provide your own api key from: "https://discord.gg/94qUZWhwFE"');
|
|
119
|
-
imageURL = gen
|
|
120
|
-
|
|
121
|
-
} else if (imageType.valideElectronImagineModels.includes(model)) {
|
|
111
|
+
} else if (imageType.validElectronModels.includes(model)) {
|
|
122
112
|
const gen = await electronImagine({ ApiKey: Api_Key as string, prompt: translatedText.text, modelName: model });
|
|
123
113
|
if (gen === null) throw new Error('this model reached rate limit. Provide your own api key from: "https://discord.gg/94qUZWhwFE"');
|
|
124
|
-
imageURL = gen
|
|
125
|
-
} else if (model === 'dalle') {
|
|
126
|
-
imageURL = await rsnAPI({ API_KEY: Api_Key, prompt: translatedText.text, apiName: 'dalle' });
|
|
114
|
+
imageURL = gen as string
|
|
127
115
|
} else {
|
|
128
116
|
throw new Error("Invalid model provided. Please check docs/npm page for valid models.");
|
|
129
117
|
}
|
|
@@ -649,14 +637,13 @@ async function ApexChat(model: string, prompt: string, { userId, memory, limit,
|
|
|
649
637
|
return geminiResponse
|
|
650
638
|
}
|
|
651
639
|
|
|
652
|
-
|
|
653
640
|
let enhancedPrompt: string = prompt;
|
|
654
641
|
let historyChat: string = `- This is Previous chat history between you (System) and the user (User)\n`;
|
|
655
642
|
let commandString: string = ''
|
|
656
643
|
if (instruction) {
|
|
657
644
|
commandString = `- Given Constant instruction for the System (AI) to abide and to always follow:\n${instruction}\n\n`
|
|
658
645
|
}
|
|
659
|
-
if (memory && userId
|
|
646
|
+
if (memory && userId) {
|
|
660
647
|
|
|
661
648
|
const userHistoryResult = (await db.find(`${userId}`, { userId })).results?.history || [];
|
|
662
649
|
const historyItems = Array.isArray(userHistoryResult) ? userHistoryResult.slice(-(limit ?? 12)) : [];
|
|
@@ -698,33 +685,55 @@ async function ApexChat(model: string, prompt: string, { userId, memory, limit,
|
|
|
698
685
|
}
|
|
699
686
|
}
|
|
700
687
|
|
|
701
|
-
async function processChunk(
|
|
688
|
+
async function processChunk(
|
|
689
|
+
model: string,
|
|
690
|
+
prompt: string,
|
|
691
|
+
{ ApiKey, personality }: { ApiKey?: string; personality?: string }
|
|
692
|
+
): Promise<string> {
|
|
693
|
+
const validOptions = await validateModels();
|
|
702
694
|
let response: string;
|
|
695
|
+
|
|
703
696
|
switch (true) {
|
|
704
|
-
case
|
|
705
|
-
response = (
|
|
697
|
+
case validOptions.validHercChatModels.includes(model):
|
|
698
|
+
response = (
|
|
699
|
+
await hercai.question({
|
|
700
|
+
model: model as ChatModelOption,
|
|
701
|
+
content: prompt,
|
|
702
|
+
personality
|
|
703
|
+
})
|
|
704
|
+
).reply;
|
|
706
705
|
break;
|
|
707
|
-
|
|
706
|
+
|
|
707
|
+
case validOptions.validotherChatModels.includes(model):
|
|
708
708
|
response = await otherChatModels({ modelName: model as any, prompt });
|
|
709
709
|
break;
|
|
710
|
-
|
|
711
|
-
|
|
710
|
+
|
|
711
|
+
case validOptions.validgroqChatModels.includes(model):
|
|
712
|
+
response = await chatGroq({
|
|
713
|
+
API_KEY: ApiKey,
|
|
714
|
+
apiName: model,
|
|
715
|
+
prompt,
|
|
716
|
+
instruction: personality
|
|
717
|
+
});
|
|
712
718
|
break;
|
|
713
|
-
|
|
714
|
-
|
|
719
|
+
|
|
720
|
+
case validOptions.validElectronModels.includes(model):
|
|
721
|
+
response = (await electronChat({
|
|
722
|
+
ApiKey,
|
|
723
|
+
prompt,
|
|
724
|
+
instruction: personality,
|
|
725
|
+
modelName: model
|
|
726
|
+
})) as string;
|
|
715
727
|
break;
|
|
716
|
-
|
|
717
|
-
response = await electronChat({ ApiKey, prompt, instruction: personality, modelName: model });
|
|
718
|
-
break;
|
|
719
|
-
case model === 'gpt-4o':
|
|
720
|
-
response = await gpt4o({ ApiKey, prompt });
|
|
721
|
-
break;
|
|
728
|
+
|
|
722
729
|
default:
|
|
723
|
-
throw new Error(
|
|
730
|
+
throw new Error("Invalid model.");
|
|
724
731
|
}
|
|
732
|
+
|
|
725
733
|
return response;
|
|
726
734
|
}
|
|
727
735
|
|
|
736
|
+
|
|
728
737
|
async function checkJobStatus(jobId: string): Promise<string | null> {
|
|
729
738
|
try {
|
|
730
739
|
while (true) {
|
package/lib/ai/functions/draw.ts
CHANGED
|
@@ -13,8 +13,6 @@ import axios from "axios";
|
|
|
13
13
|
import { validateModels } from './validOptions';
|
|
14
14
|
import api from "api";
|
|
15
15
|
import { groqAnalyzer } from "../utils";
|
|
16
|
-
import { rsnAPI } from "../modals-chat/rsn/rsnChat";
|
|
17
|
-
import { fresedImagine } from "../modals-chat/freesedgpt/fresedImagine";
|
|
18
16
|
import { electronImagine } from "../modals-chat/electronHub/imageModels";
|
|
19
17
|
|
|
20
18
|
const sdk: any = api("@prodia/v1.3.0#be019b2kls0gqss3");
|
|
@@ -35,7 +33,7 @@ async function aiImagine(
|
|
|
35
33
|
) {
|
|
36
34
|
const maxRetryAttempts = 4;
|
|
37
35
|
const retryInterval = 5000;
|
|
38
|
-
const imageType = await validateModels;
|
|
36
|
+
const imageType = await validateModels();
|
|
39
37
|
const attachData: AttachmentData[] = [];
|
|
40
38
|
const buttonsRow1: ButtonBuilder[] = [];
|
|
41
39
|
const imageUrls: string[] = [];
|
|
@@ -571,12 +569,8 @@ async function aiImagine(
|
|
|
571
569
|
const generateResponse = await sdk.sdxlGenerate({ model: imageModal, prompt: translatedText.text, ...enhancer });
|
|
572
570
|
const generatedJobId = generateResponse.data.job;
|
|
573
571
|
response = await checkJobStatus(generatedJobId);
|
|
574
|
-
} else if (imageType.
|
|
575
|
-
response = await fresedImagine(translatedText.text, imageModal, imageAPIS?.freesedGPTApi as any);
|
|
576
|
-
} else if (imageType.valideElectronImagineModels.includes(imageModal)) {
|
|
572
|
+
} else if (imageType.validElectronModels.includes(imageModal)) {
|
|
577
573
|
response = await electronImagine({ ApiKey: imageAPIS?.electronHubKey as any, prompt: translatedText.text, modelName: imageModal });
|
|
578
|
-
} else if (imageModal === 'dalle') {
|
|
579
|
-
response = await rsnAPI({ API_KEY: imageAPIS?.rsnAPI, prompt: translatedText.text, apiName: 'dalle' });
|
|
580
574
|
} else {
|
|
581
575
|
throw new Error("Invalid modal name.");
|
|
582
576
|
}
|
|
@@ -1,76 +1,101 @@
|
|
|
1
1
|
import api from "api";
|
|
2
|
+
import Groq from 'groq-sdk';
|
|
3
|
+
import OpenAI from "openai";
|
|
2
4
|
|
|
3
5
|
const sdk = api("@prodia/v1.3.0#be019b2kls0gqss3");
|
|
4
|
-
sdk.auth(
|
|
6
|
+
sdk.auth("43435e1c-cab1-493f-a224-f51e4b97ce8d");
|
|
5
7
|
|
|
6
|
-
export const hercChatModels = [
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export const otherChatModel = ['apexai', 'facebook_ai', 'yi_34b', 'starChat'];
|
|
12
|
-
export const fresedgptModels = ['real-cartoon-xl-v6', 'flux-schnell', 'gpt-4o'];
|
|
8
|
+
export const hercChatModels = [
|
|
9
|
+
"v3", "v3-32k", "turbo", "turbo-16k", "gemini",
|
|
10
|
+
"llama3-70b", "llama3-8b", "mixtral-8x7b",
|
|
11
|
+
"gemma-7b", "gemma2-9b"
|
|
12
|
+
];
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
const [SDModels, SDXLModels, samplers] = await Promise.all([
|
|
16
|
-
sdModels(),
|
|
17
|
-
sdxlModels(),
|
|
18
|
-
sampler()
|
|
19
|
-
]);
|
|
14
|
+
export const otherChatModel = ["apexai", "facebook_ai", "yi_34b", "starChat"];
|
|
20
15
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
16
|
+
const initializeGroqInstance = () => {
|
|
17
|
+
return new Groq({ apiKey: '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' });
|
|
18
|
+
};
|
|
19
|
+
export async function electronHubModels(apiKey?: string): Promise<string[]> {
|
|
20
|
+
const key = apiKey || "ek-am4V5cXBlrCvRx7Ts3TXmvki5CTP3HZst4bNAbyH0XSkzmOqG1";
|
|
21
|
+
const openai = new OpenAI({
|
|
22
|
+
apiKey: key,
|
|
23
|
+
baseURL: "https://api.electronhub.top/v1",
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const models = await openai.models.list();
|
|
27
|
+
return models.data.map((model: any) => model.id);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const groqChatModels = async (groqInstance: any) => {
|
|
31
|
+
const allModels = await groqInstance.models.list();
|
|
32
|
+
|
|
33
|
+
const filteredModels = allModels.data.filter((model: any) =>
|
|
34
|
+
!model.id.startsWith("whisper") &&
|
|
35
|
+
!model.id.startsWith("llava") &&
|
|
36
|
+
!model.id.startsWith("distil-whisper")
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
return filteredModels.map((model: any) => model.id);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
async function initializeValidOptions() {
|
|
43
|
+
const groq = initializeGroqInstance();
|
|
31
44
|
|
|
45
|
+
const [SDModels, SDXLModels, samplers, groqModels, electronModels] = await Promise.all([
|
|
46
|
+
sdModels(),
|
|
47
|
+
sdxlModels(),
|
|
48
|
+
sampler(),
|
|
49
|
+
groqChatModels(groq),
|
|
50
|
+
electronHubModels()
|
|
51
|
+
]);
|
|
32
52
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
const HercImageModels = [
|
|
54
|
+
"v3", "lexica", "prodia", "prodia-v2", "simurg",
|
|
55
|
+
"animefy", "raava", "shonin"
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
validHercChatModels: hercChatModels,
|
|
60
|
+
validgroqChatModels: groqModels,
|
|
61
|
+
validElectronModels: electronModels,
|
|
62
|
+
validHercaiModels: HercImageModels,
|
|
63
|
+
validProdiaModels: SDModels,
|
|
64
|
+
validotherChatModels: otherChatModel,
|
|
65
|
+
validEnhancers: [
|
|
66
|
+
"ESRGAN_4x", "Lanczos", "Nearest", "LDSR",
|
|
67
|
+
"R-ESRGAN 4x+", "R-ESRGAN 4x+ Anime6B",
|
|
68
|
+
"ScuNET GAN", "ScuNET PSNR", "SwinIR 4x"
|
|
69
|
+
],
|
|
70
|
+
validSamplers: samplers,
|
|
71
|
+
validSXDL: SDXLModels,
|
|
72
|
+
validImgStyle: [
|
|
73
|
+
"3d-model", "analog-film", "anime", "cinematic",
|
|
74
|
+
"comic-book", "digital-art", "enhance", "isometric",
|
|
75
|
+
"fantasy-art", "line-art", "low-poly", "neon-punk",
|
|
76
|
+
"origami", "photographic", "pixel-art", "texture",
|
|
77
|
+
"craft-clay"
|
|
78
|
+
],
|
|
79
|
+
allModels: [
|
|
80
|
+
...SDModels, ...SDXLModels, ...HercImageModels,
|
|
81
|
+
...hercChatModels, ...otherChatModel, ...groqModels, ...electronModels
|
|
82
|
+
]
|
|
83
|
+
};
|
|
57
84
|
}
|
|
58
85
|
|
|
59
|
-
export const validateModels = initializeValidOptions();
|
|
86
|
+
export const validateModels = async () => await initializeValidOptions();
|
|
60
87
|
|
|
61
88
|
async function sdModels(): Promise<string[]> {
|
|
62
|
-
|
|
63
|
-
|
|
89
|
+
const SDModals = await sdk.listModels();
|
|
90
|
+
return SDModals.data;
|
|
64
91
|
}
|
|
65
92
|
|
|
66
93
|
async function sdxlModels(): Promise<string[]> {
|
|
67
|
-
|
|
68
|
-
|
|
94
|
+
const SDXLModals = await sdk.listSdxlModels();
|
|
95
|
+
return SDXLModals.data;
|
|
69
96
|
}
|
|
70
97
|
|
|
71
|
-
|
|
72
98
|
async function sampler(): Promise<string[]> {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
99
|
+
const Samplers = await sdk.listSamplers();
|
|
100
|
+
return Samplers.data;
|
|
101
|
+
}
|
|
@@ -1,66 +1,63 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { electronChatModels } from '../../functions/validOptions';
|
|
3
|
-
|
|
1
|
+
import OpenAI from "openai";
|
|
4
2
|
export async function electronChat({
|
|
5
3
|
ApiKey,
|
|
6
4
|
prompt,
|
|
7
5
|
modelName,
|
|
8
|
-
instruction
|
|
6
|
+
instruction,
|
|
9
7
|
}: {
|
|
10
|
-
ApiKey?: string
|
|
11
|
-
prompt: string
|
|
12
|
-
modelName: string
|
|
13
|
-
instruction?: string
|
|
8
|
+
ApiKey?: string;
|
|
9
|
+
prompt: string;
|
|
10
|
+
modelName: string;
|
|
11
|
+
instruction?: string;
|
|
14
12
|
}) {
|
|
13
|
+
|
|
15
14
|
|
|
16
|
-
if (
|
|
17
|
-
|
|
15
|
+
if (modelName === "claude-3-sonnet-200k") {
|
|
16
|
+
modelName = "claude-3-sonnet-20240229";
|
|
17
|
+
} else if (modelName === "claude-3.5-sonnet-200k") {
|
|
18
|
+
modelName = "claude-3.5-sonnet-20240620";
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
try {
|
|
22
|
+
const apiKey = ApiKey || "ek-am4V5cXBlrCvRx7Ts3TXmvki5CTP3HZst4bNAbyH0XSkzmOqG1";
|
|
23
|
+
const openai = new OpenAI({
|
|
24
|
+
apiKey: apiKey,
|
|
25
|
+
baseURL: "https://api.electronhub.top/v1",
|
|
26
|
+
});
|
|
23
27
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (modelName === 'claude-3-sonnet-200k') {
|
|
29
|
-
modelName = 'claude-3-sonnet-20240229';
|
|
30
|
-
} else if (modelName === 'claude-3.5-sonnet-200k') {
|
|
31
|
-
modelName = 'claude-3.5-sonnet-20240620';
|
|
32
|
-
}
|
|
28
|
+
const models = await openai.models.list();
|
|
29
|
+
|
|
30
|
+
const modelExists = models.data.some((model: any) => model.id === modelName);
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
);
|
|
32
|
+
if (!modelExists) {
|
|
33
|
+
throw new Error('Invalid model name please check out Electron hub models for more info.')
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const completion = await openai.chat.completions.create({
|
|
37
|
+
model: modelName,
|
|
38
|
+
messages: [
|
|
39
|
+
{"role": "system", "content": `${instruction}`},
|
|
40
|
+
{"role": "user", "content": `${prompt}`}
|
|
41
|
+
]
|
|
42
|
+
});
|
|
48
43
|
|
|
49
|
-
|
|
50
|
-
return response.data.choices[0].message.content;
|
|
44
|
+
return completion.choices[0]?.message?.content;
|
|
51
45
|
} catch (e: any) {
|
|
52
46
|
if (e.response) {
|
|
53
47
|
if (e.response.status === 429) {
|
|
54
|
-
throw new Error(
|
|
48
|
+
throw new Error(
|
|
49
|
+
"Rate limit exceeded. Please join the server at https://discord.gg/83XcjD8vgW for an API key."
|
|
50
|
+
);
|
|
55
51
|
} else if (e.response.status === 500) {
|
|
56
|
-
throw new Error(
|
|
52
|
+
throw new Error("Server error. Please try again later.");
|
|
57
53
|
} else {
|
|
58
|
-
console.error(
|
|
54
|
+
console.error("Error generating response:", e.response.data);
|
|
59
55
|
throw e;
|
|
60
56
|
}
|
|
61
57
|
} else {
|
|
62
|
-
console.error(
|
|
58
|
+
console.error("Error generating response:", e.message);
|
|
63
59
|
throw e;
|
|
64
60
|
}
|
|
65
61
|
}
|
|
66
|
-
}
|
|
62
|
+
}
|
|
63
|
+
|
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const validModels = [
|
|
4
|
-
'sdxl-lightning',
|
|
5
|
-
'kandinsky-3',
|
|
6
|
-
'dall-e-3',
|
|
7
|
-
'niji-v6',
|
|
8
|
-
'niji-v5',
|
|
9
|
-
'midjourney-v6.1',
|
|
10
|
-
'midjourney-v5',
|
|
11
|
-
'flux-dev',
|
|
12
|
-
'flux-pro'
|
|
13
|
-
];
|
|
1
|
+
import OpenAI from "openai";
|
|
14
2
|
|
|
15
3
|
export async function electronImagine({
|
|
16
4
|
ApiKey,
|
|
@@ -22,30 +10,44 @@ export async function electronImagine({
|
|
|
22
10
|
modelName: string
|
|
23
11
|
}) {
|
|
24
12
|
|
|
25
|
-
|
|
26
|
-
|
|
13
|
+
const apiKey = ApiKey || "ek-am4V5cXBlrCvRx7Ts3TXmvki5CTP3HZst4bNAbyH0XSkzmOqG1";
|
|
14
|
+
const openai = new OpenAI({
|
|
15
|
+
apiKey: apiKey,
|
|
16
|
+
baseURL: "https://api.electronhub.top/v1",
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const models = await openai.models.list();
|
|
20
|
+
|
|
21
|
+
const modelExists = models.data.some((model: any) => model.id === modelName);
|
|
22
|
+
|
|
23
|
+
if (!modelExists) {
|
|
24
|
+
throw new Error('Invalid model name please check out Electron hub models for more info.')
|
|
27
25
|
}
|
|
28
26
|
|
|
29
27
|
try {
|
|
30
|
-
const response = await
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
n: 1
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
headers: {
|
|
39
|
-
'Authorization': `Bearer ${ApiKey || 'ek-nFO8tz6qiu5cJ31lwCfPZNNrxFZLsJYou6yx4X1FS2Jyr2dm0a'}`,
|
|
40
|
-
'Content-Type': 'application/json'
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
);
|
|
28
|
+
const response = await openai.images.generate({
|
|
29
|
+
model: modelName,
|
|
30
|
+
prompt: prompt,
|
|
31
|
+
n: 1,
|
|
32
|
+
});
|
|
44
33
|
|
|
45
34
|
const imagesUrl = response.data;
|
|
46
|
-
return imagesUrl
|
|
35
|
+
return imagesUrl[0].url;
|
|
47
36
|
} catch (e: any) {
|
|
48
|
-
|
|
49
|
-
|
|
37
|
+
if (e.response) {
|
|
38
|
+
if (e.response.status === 429) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
"Rate limit exceeded. Please join the server at https://discord.gg/83XcjD8vgW for an API key."
|
|
41
|
+
);
|
|
42
|
+
} else if (e.response.status === 500) {
|
|
43
|
+
throw new Error("Server error. Please try again later.");
|
|
44
|
+
} else {
|
|
45
|
+
console.error("Error generating response:", e.response.data);
|
|
46
|
+
throw e;
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
console.error("Error generating response:", e.message);
|
|
50
|
+
throw e;
|
|
51
|
+
}
|
|
50
52
|
}
|
|
51
53
|
}
|
|
@@ -7,24 +7,34 @@ interface groqOptions {
|
|
|
7
7
|
instruction?: string;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
// Define your own type for message parameters
|
|
11
10
|
interface ChatCompletionMessageParam {
|
|
12
11
|
role: 'system' | 'user' | 'assistant';
|
|
13
12
|
content: string;
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
const
|
|
15
|
+
const getModels = async (groqInstance: any) => {
|
|
16
|
+
const allModels = await groqInstance.models.list();
|
|
17
|
+
|
|
18
|
+
const filteredModels = allModels.data.filter((model: any) =>
|
|
19
|
+
!model.id.startsWith('whisper') && !model.id.startsWith('llava') && !model.id.startsWith('distil-whisper')
|
|
20
|
+
);
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return `Invalid API name: ${apiName}. Please provide one of the following: ${validGroqApiNames.join(', ')}`;
|
|
21
|
-
}
|
|
22
|
+
return filteredModels;
|
|
23
|
+
};
|
|
22
24
|
|
|
25
|
+
export async function chatGroq({ API_KEY, prompt, apiName, instruction }: groqOptions): Promise<string> {
|
|
23
26
|
try {
|
|
24
27
|
const groq = new Groq({
|
|
25
28
|
apiKey: API_KEY || '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',
|
|
26
29
|
});
|
|
27
30
|
|
|
31
|
+
const models = await getModels(groq);
|
|
32
|
+
const modelExists = models.some((model: any) => model.id === apiName);
|
|
33
|
+
|
|
34
|
+
if (!modelExists) {
|
|
35
|
+
throw new Error('Invalid model name provided. Please check the available models on Groq.');
|
|
36
|
+
}
|
|
37
|
+
|
|
28
38
|
const messages: ChatCompletionMessageParam[] = [];
|
|
29
39
|
|
|
30
40
|
if (instruction) {
|
|
@@ -65,4 +75,4 @@ export async function chatGroq({ API_KEY, prompt, apiName, instruction }: groqOp
|
|
|
65
75
|
return 'Unknown error occurred.';
|
|
66
76
|
}
|
|
67
77
|
}
|
|
68
|
-
}
|
|
78
|
+
}
|
|
@@ -19,7 +19,6 @@ async function convertUrlToDataUrl(url: string): Promise<string> {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
23
22
|
export async function groqAnalyzer({ imgURL, ApiKey, prompt }: GroqAnalyzerOptions): Promise<string> {
|
|
24
23
|
try {
|
|
25
24
|
const groq = new Groq({
|
|
@@ -28,7 +27,6 @@ export async function groqAnalyzer({ imgURL, ApiKey, prompt }: GroqAnalyzerOptio
|
|
|
28
27
|
|
|
29
28
|
const imageDataUrl = await convertUrlToDataUrl(imgURL);
|
|
30
29
|
|
|
31
|
-
// @ts-ignore
|
|
32
30
|
const chatCompletion = await groq.chat.completions.create({
|
|
33
31
|
messages: [
|
|
34
32
|
{
|
|
@@ -33,13 +33,11 @@ async function createReadableStream(filepathOrUrl: string): Promise<NodeJS.Reada
|
|
|
33
33
|
}
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
// @ts-ignore: Ignore type checking for this line
|
|
37
36
|
response.pipe(file);
|
|
38
37
|
|
|
39
38
|
file.on('finish', () => {
|
|
40
39
|
file.close(() => {
|
|
41
40
|
if (fileSize <= maxFileSizeBytes) {
|
|
42
|
-
// @ts-ignore: Ignore type checking for this line
|
|
43
41
|
resolve(fs.createReadStream(tempFilePath));
|
|
44
42
|
}
|
|
45
43
|
});
|
|
@@ -55,7 +53,6 @@ async function createReadableStream(filepathOrUrl: string): Promise<NodeJS.Reada
|
|
|
55
53
|
if (fileSize > maxFileSizeBytes) {
|
|
56
54
|
return 'File size exceeds the limit (25MB)';
|
|
57
55
|
}
|
|
58
|
-
// @ts-ignore: Ignore type checking for this line
|
|
59
56
|
return fs.createReadStream(filepathOrUrl);
|
|
60
57
|
}
|
|
61
58
|
}
|