apexify.js 4.7.4 → 4.7.6
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/cjs/ai/ApexAI.d.ts +2 -0
- package/dist/cjs/ai/ApexAI.d.ts.map +1 -1
- package/dist/cjs/ai/ApexAI.js +4 -4
- package/dist/cjs/ai/ApexAI.js.map +1 -1
- package/dist/cjs/ai/ApexModules.js +1 -1
- package/dist/cjs/ai/ApexModules.js.map +1 -1
- package/dist/cjs/ai/modals-chat/groq/imageAnalyzer.d.ts +2 -2
- package/dist/cjs/ai/modals-chat/groq/imageAnalyzer.d.ts.map +1 -1
- package/dist/cjs/ai/modals-chat/groq/imageAnalyzer.js +46 -23
- package/dist/cjs/ai/modals-chat/groq/imageAnalyzer.js.map +1 -1
- package/dist/cjs/canvas/utils/Image/imageProperties.d.ts.map +1 -1
- package/dist/cjs/canvas/utils/Image/imageProperties.js +21 -4
- package/dist/cjs/canvas/utils/Image/imageProperties.js.map +1 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +0 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/ai/ApexAI.d.ts +2 -0
- package/dist/esm/ai/ApexAI.d.ts.map +1 -1
- package/dist/esm/ai/ApexAI.js +4 -4
- package/dist/esm/ai/ApexAI.js.map +1 -1
- package/dist/esm/ai/ApexModules.js +1 -1
- package/dist/esm/ai/ApexModules.js.map +1 -1
- package/dist/esm/ai/modals-chat/groq/imageAnalyzer.d.ts +2 -2
- package/dist/esm/ai/modals-chat/groq/imageAnalyzer.d.ts.map +1 -1
- package/dist/esm/ai/modals-chat/groq/imageAnalyzer.js +46 -23
- package/dist/esm/ai/modals-chat/groq/imageAnalyzer.js.map +1 -1
- package/dist/esm/canvas/utils/Image/imageProperties.d.ts.map +1 -1
- package/dist/esm/canvas/utils/Image/imageProperties.js +21 -4
- package/dist/esm/canvas/utils/Image/imageProperties.js.map +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +0 -3
- package/dist/esm/index.js.map +1 -1
- package/lib/ai/ApexAI.ts +7 -5
- package/lib/ai/ApexModules.ts +2 -2
- package/lib/ai/modals-chat/groq/imageAnalyzer.ts +61 -39
- package/lib/canvas/utils/Image/imageProperties.ts +24 -4
- package/lib/index.ts +0 -3
- package/package.json +2 -2
package/lib/ai/ApexAI.ts
CHANGED
|
@@ -93,10 +93,12 @@ export interface Options {
|
|
|
93
93
|
Api_Keys?: {
|
|
94
94
|
groq_API?: string;
|
|
95
95
|
electronHub_Key?: string
|
|
96
|
-
};
|
|
96
|
+
};
|
|
97
97
|
memory?: {
|
|
98
98
|
memoryOn?: boolean;
|
|
99
99
|
id?: string;
|
|
100
|
+
threshold?: number;
|
|
101
|
+
limit?: number;
|
|
100
102
|
};
|
|
101
103
|
typeWriting?: {
|
|
102
104
|
enable?: boolean;
|
|
@@ -234,7 +236,7 @@ export async function ApexAI(message: Message, ApexOptions: Options) {
|
|
|
234
236
|
console.error("Missing Groq API Key.");
|
|
235
237
|
continue;
|
|
236
238
|
}
|
|
237
|
-
prompt += `\n> Image analysis:\n${await groqAnalyzer({
|
|
239
|
+
prompt += `\n> Image analysis:\n${await groqAnalyzer({ img: url, ApiKey: Api_Keys.groq_API })}`;
|
|
238
240
|
}
|
|
239
241
|
|
|
240
242
|
|
|
@@ -269,7 +271,7 @@ export async function ApexAI(message: Message, ApexOptions: Options) {
|
|
|
269
271
|
const firstAttachment = fetchedMessage.attachments?.first();
|
|
270
272
|
if (firstAttachment && /\.(png|jpg|jpeg|webp)$/i.test(firstAttachment.url)) {
|
|
271
273
|
prevReply += await groqAnalyzer({
|
|
272
|
-
|
|
274
|
+
img: firstAttachment.url,
|
|
273
275
|
ApiKey: Api_Keys?.groq_API,
|
|
274
276
|
prompt,
|
|
275
277
|
});
|
|
@@ -331,7 +333,7 @@ export async function ApexAI(message: Message, ApexOptions: Options) {
|
|
|
331
333
|
instruction += `\n\nThe image has already been generated. Do not attempt to generate or describe another image. Instead, provide feedback, thoughts, or a critique based on the given prompt:\n\n`;
|
|
332
334
|
}
|
|
333
335
|
|
|
334
|
-
aiResponse = await ApexChat(chat?.chatModel as string, prompt, { instruction, memory: chat?.memory?.memoryOn, userId: chat?.memory?.id, limit:
|
|
336
|
+
aiResponse = await ApexChat(chat?.chatModel as string, prompt, { instruction, memory: chat?.memory?.memoryOn, userId: chat?.memory?.id, limit: chat?.memory?.limit, threshold: chat?.memory?.threshold });
|
|
335
337
|
}
|
|
336
338
|
|
|
337
339
|
else if (voiceEnabled) {
|
|
@@ -354,7 +356,7 @@ export async function ApexAI(message: Message, ApexOptions: Options) {
|
|
|
354
356
|
instruction += `\n\nThe image has already been generated. Do not attempt to generate or describe another image. Instead, provide feedback, thoughts, or a critique based on the given prompt:\n\n`;
|
|
355
357
|
}
|
|
356
358
|
|
|
357
|
-
aiResponse = await ApexChat(chat?.chatModel as string, prompt, { instruction, memory: chat?.memory?.memoryOn, userId: chat?.memory?.id, limit:
|
|
359
|
+
aiResponse = await ApexChat(chat?.chatModel as string, prompt, { instruction, memory: chat?.memory?.memoryOn, userId: chat?.memory?.id, limit: chat?.memory?.limit, threshold: chat?.memory?.threshold });
|
|
358
360
|
|
|
359
361
|
aiResponse = await ApexText2Speech({ modelName: voice?.voiceModel, inputText: aiResponse, personality: voice?.characterName });
|
|
360
362
|
}
|
package/lib/ai/ApexModules.ts
CHANGED
|
@@ -41,7 +41,7 @@ type ChatModelOption = "v3" | "v3-32k" | "turbo" | "turbo-16k" | "gemini" ;
|
|
|
41
41
|
type hercmodals = "v3" | "lexica" | "prodia" | "animefy" | "raava" | "shonin" | "simurg";
|
|
42
42
|
|
|
43
43
|
async function ApexImagine(model: string, prompt: string, options?: ApexImagineOptions): Promise<string[] | undefined> {
|
|
44
|
-
let imageURL: string |
|
|
44
|
+
let imageURL: string | Buffer = '';
|
|
45
45
|
let response: string[] = [];
|
|
46
46
|
const imageType = await validateModels();
|
|
47
47
|
const { Api_Key = 'eaebff6e-c7b2-477c-8edd-9aa91becf1e3', nsfw = false, deepCheck = false, nsfwWords = [], count = 2, negative_prompt = "", sampler = "DPM++ 2M Karras", height = 1024, width = 1024, cfg_scale = 9, steps = 20, seed = -1, image_style = "cinematic" } = options ?? {};
|
|
@@ -570,7 +570,7 @@ async function ApexImagine(model: string, prompt: string, options?: ApexImagineO
|
|
|
570
570
|
let shouldExclude = false;
|
|
571
571
|
|
|
572
572
|
if (nsfw === true) {
|
|
573
|
-
const caption = await groqAnalyzer({
|
|
573
|
+
const caption = await groqAnalyzer({ img: imageURL, prompt });
|
|
574
574
|
if (!caption) return;
|
|
575
575
|
shouldExclude = NSFWWORDS.some(word => caption.includes(word));
|
|
576
576
|
shouldExclude = nsfwWords.some(word => caption.includes(word));
|
|
@@ -1,61 +1,83 @@
|
|
|
1
|
-
import Groq from
|
|
2
|
-
import axios from
|
|
1
|
+
import Groq from "groq-sdk";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import path from "path";
|
|
3
5
|
|
|
4
6
|
interface GroqAnalyzerOptions {
|
|
5
|
-
|
|
7
|
+
img: string | Buffer;
|
|
6
8
|
ApiKey?: string;
|
|
7
9
|
prompt?: string;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
async function convertUrlToDataUrl(url: string): Promise<string> {
|
|
11
13
|
try {
|
|
12
|
-
const response = await axios.get(url, { responseType:
|
|
13
|
-
const buffer = Buffer.from(response.data,
|
|
14
|
-
|
|
15
|
-
return dataUrl;
|
|
14
|
+
const response = await axios.get(url, { responseType: "arraybuffer" });
|
|
15
|
+
const buffer = Buffer.from(response.data, "binary");
|
|
16
|
+
return `data:${response.headers["content-type"]};base64,${buffer.toString("base64")}`;
|
|
16
17
|
} catch (error) {
|
|
17
|
-
console.error(
|
|
18
|
-
throw new Error(
|
|
18
|
+
console.error("Error converting URL to Data URL:", error);
|
|
19
|
+
throw new Error("Failed to convert image URL to data URL");
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
async function convertFileToDataUrl(filePath: string): Promise<string> {
|
|
24
|
+
try {
|
|
25
|
+
const absolutePath = path.resolve(filePath);
|
|
26
|
+
const buffer = fs.readFileSync(absolutePath);
|
|
27
|
+
const mimeType = "image/png";
|
|
28
|
+
return `data:${mimeType};base64,${buffer.toString("base64")}`;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.error("Error converting file to Data URL:", error);
|
|
31
|
+
throw new Error("Failed to convert file to data URL");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function convertBufferToDataUrl(buffer: Buffer): string {
|
|
36
|
+
const mimeType = "image/png"; // Adjust dynamically if needed
|
|
37
|
+
return `data:${mimeType};base64,${buffer.toString("base64")}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function groqAnalyzer({ img, ApiKey, prompt }: GroqAnalyzerOptions): Promise<string> {
|
|
23
41
|
try {
|
|
24
42
|
const groq = new Groq({
|
|
25
|
-
apiKey: ApiKey ||
|
|
43
|
+
apiKey: ApiKey || "your-api-key-here",
|
|
26
44
|
});
|
|
27
45
|
|
|
28
|
-
|
|
46
|
+
let imageDataUrl: string;
|
|
47
|
+
|
|
48
|
+
if (typeof img === "string") {
|
|
49
|
+
if (img.startsWith("http")) {
|
|
50
|
+
imageDataUrl = await convertUrlToDataUrl(img);
|
|
51
|
+
} else {
|
|
52
|
+
imageDataUrl = await convertFileToDataUrl(img);
|
|
53
|
+
}
|
|
54
|
+
} else if (Buffer.isBuffer(img)) {
|
|
55
|
+
imageDataUrl = convertBufferToDataUrl(img);
|
|
56
|
+
} else {
|
|
57
|
+
throw new Error("Invalid image input. Must be a URL, file path, or Buffer.");
|
|
58
|
+
}
|
|
29
59
|
|
|
30
60
|
const chatCompletion = await groq.chat.completions.create({
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
model: 'llama-3.2-90b-vision-preview',
|
|
49
|
-
temperature: 0,
|
|
50
|
-
max_tokens: 8192,
|
|
51
|
-
top_p: 1,
|
|
52
|
-
stream: false,
|
|
53
|
-
stop: null,
|
|
54
|
-
});
|
|
55
|
-
|
|
61
|
+
messages: [
|
|
62
|
+
{
|
|
63
|
+
role: "user",
|
|
64
|
+
content: [
|
|
65
|
+
{ type: "text", text: prompt || "" },
|
|
66
|
+
{ type: "image_url", image_url: { url: imageDataUrl } },
|
|
67
|
+
],
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
model: "llama-3.2-90b-vision-preview",
|
|
71
|
+
temperature: 0,
|
|
72
|
+
max_tokens: 8192,
|
|
73
|
+
top_p: 1,
|
|
74
|
+
stream: false,
|
|
75
|
+
stop: null,
|
|
76
|
+
});
|
|
77
|
+
|
|
56
78
|
return chatCompletion.choices[0].message.content as string;
|
|
57
79
|
} catch (error) {
|
|
58
|
-
console.error(
|
|
59
|
-
return
|
|
80
|
+
console.error("Error in groqAnalyzer:", error);
|
|
81
|
+
return "❌ Error occurred while analyzing the image.";
|
|
60
82
|
}
|
|
61
83
|
}
|
|
@@ -643,6 +643,7 @@ export function objectRadius(
|
|
|
643
643
|
ctx.beginPath();
|
|
644
644
|
|
|
645
645
|
if (borderRadius === "circular") {
|
|
646
|
+
// Draw a circular shape
|
|
646
647
|
const circleRadius = Math.min(width, height) / 2;
|
|
647
648
|
ctx.arc(x + width / 2, y + height / 2, circleRadius, 0, 2 * Math.PI);
|
|
648
649
|
} else if (borderRadius > 0) {
|
|
@@ -651,16 +652,34 @@ export function objectRadius(
|
|
|
651
652
|
borderPosition.toLowerCase().split(",").map((s) => s.trim())
|
|
652
653
|
);
|
|
653
654
|
|
|
654
|
-
|
|
655
|
-
const
|
|
656
|
-
|
|
657
|
-
|
|
655
|
+
// **Correct Grouping**
|
|
656
|
+
const roundTopLeft = selectedPositions.has("all") ||
|
|
657
|
+
selectedPositions.has("top-left") ||
|
|
658
|
+
selectedPositions.has("top") ||
|
|
659
|
+
selectedPositions.has("left");
|
|
658
660
|
|
|
661
|
+
const roundTopRight = selectedPositions.has("all") ||
|
|
662
|
+
selectedPositions.has("top-right") ||
|
|
663
|
+
selectedPositions.has("top") ||
|
|
664
|
+
selectedPositions.has("right");
|
|
665
|
+
|
|
666
|
+
const roundBottomRight = selectedPositions.has("all") ||
|
|
667
|
+
selectedPositions.has("bottom-right") ||
|
|
668
|
+
selectedPositions.has("bottom") ||
|
|
669
|
+
selectedPositions.has("right");
|
|
670
|
+
|
|
671
|
+
const roundBottomLeft = selectedPositions.has("all") ||
|
|
672
|
+
selectedPositions.has("bottom-left") ||
|
|
673
|
+
selectedPositions.has("bottom") ||
|
|
674
|
+
selectedPositions.has("left");
|
|
675
|
+
|
|
676
|
+
// **Assign correct radii**
|
|
659
677
|
const tl = roundTopLeft ? br : 0;
|
|
660
678
|
const tr = roundTopRight ? br : 0;
|
|
661
679
|
const brR = roundBottomRight ? br : 0;
|
|
662
680
|
const bl = roundBottomLeft ? br : 0;
|
|
663
681
|
|
|
682
|
+
// **Draw rounded rectangle**
|
|
664
683
|
ctx.moveTo(x + tl, y);
|
|
665
684
|
ctx.lineTo(x + width - tr, y);
|
|
666
685
|
if (tr > 0) ctx.arc(x + width - tr, y + tr, tr, -Math.PI / 2, 0, false);
|
|
@@ -671,6 +690,7 @@ export function objectRadius(
|
|
|
671
690
|
ctx.lineTo(x, y + tl);
|
|
672
691
|
if (tl > 0) ctx.arc(x + tl, y + tl, tl, Math.PI, -Math.PI / 2, false);
|
|
673
692
|
} else {
|
|
693
|
+
// Default: Draw normal rectangle
|
|
674
694
|
ctx.rect(x, y, width, height);
|
|
675
695
|
}
|
|
676
696
|
|
package/lib/index.ts
CHANGED
|
@@ -10,7 +10,6 @@ const RESET = "\x1b[0m";
|
|
|
10
10
|
const packageJsonPath = path.resolve(process.cwd(), "package.json");
|
|
11
11
|
let packageJson: Record<string, any> = {};
|
|
12
12
|
|
|
13
|
-
// ** Load package.json Safely **
|
|
14
13
|
try {
|
|
15
14
|
packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
16
15
|
} catch (error) {
|
|
@@ -28,7 +27,6 @@ const getLibraryVersion = (library: string): string => {
|
|
|
28
27
|
);
|
|
29
28
|
};
|
|
30
29
|
|
|
31
|
-
// ** Check Installed Version BEFORE Fetching Remote Version **
|
|
32
30
|
const installedVersion = getLibraryVersion("apexify.js");
|
|
33
31
|
|
|
34
32
|
fetch("https://registry.npmjs.com/-/v1/search?text=apexify.js")
|
|
@@ -64,7 +62,6 @@ if (!installedVersion || installedVersion === "Not installed") {
|
|
|
64
62
|
console.log(`${GREEN}✅ Apexify.js is already installed (Version: ${installedVersion}).${RESET}`);
|
|
65
63
|
}
|
|
66
64
|
|
|
67
|
-
// ✅ FIX: Do NOT uninstall automatically
|
|
68
65
|
|
|
69
66
|
import {
|
|
70
67
|
ApexAI, ApexChat, ApexImagine, ApexPainter, ApexListener, readFile,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apexify.js",
|
|
3
|
-
"version": "4.7.
|
|
3
|
+
"version": "4.7.6",
|
|
4
4
|
"description": "Unlimited AI models and Canvas library. Supports ts & js (supports front/back end).",
|
|
5
5
|
"author": "zenith-79",
|
|
6
6
|
"license": "MIT",
|
|
@@ -227,7 +227,7 @@
|
|
|
227
227
|
"dependencies": {
|
|
228
228
|
"@google/generative-ai": "^0.22.0",
|
|
229
229
|
"@napi-rs/canvas": "^0.1.53",
|
|
230
|
-
"apexify.js": "^4.7.
|
|
230
|
+
"apexify.js": "^4.7.5",
|
|
231
231
|
"axios": "^1.7.7",
|
|
232
232
|
"discord.js": "^14.18.0",
|
|
233
233
|
"fluent-ffmpeg": "^2.1.3",
|