apexify.js 4.2.4 → 4.2.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/README.md +5 -4
- package/dist/ai/ApexAI.d.ts +2 -0
- package/dist/ai/ApexAI.d.ts.map +1 -1
- package/dist/ai/ApexAI.js +126 -23
- package/dist/ai/ApexAI.js.map +1 -1
- package/dist/ai/ApexModules.d.ts +11 -1
- package/dist/ai/ApexModules.d.ts.map +1 -1
- package/dist/ai/ApexModules.js +80 -3
- package/dist/ai/ApexModules.js.map +1 -1
- package/dist/ai/ApexVoice.d.ts +1 -0
- package/dist/ai/ApexVoice.d.ts.map +1 -0
- package/dist/ai/ApexVoice.js +2 -0
- package/dist/ai/ApexVoice.js.map +1 -0
- package/dist/ai/buttons/drawMenu.js +1 -2
- package/dist/ai/buttons/drawMenu.js.map +1 -1
- package/dist/ai/buttons/tools.js +1 -2
- package/dist/ai/buttons/tools.js.map +1 -1
- package/dist/ai/functions/chunkString.js +1 -2
- package/dist/ai/functions/chunkString.js.map +1 -1
- package/dist/ai/functions/draw.js +9 -11
- package/dist/ai/functions/draw.js.map +1 -1
- package/dist/ai/functions/generateVoiceResponse.js +1 -2
- package/dist/ai/functions/generateVoiceResponse.js.map +1 -1
- package/dist/ai/functions/imageReader.js +1 -2
- package/dist/ai/functions/imageReader.js.map +1 -1
- package/dist/ai/functions/readFiles.d.ts.map +1 -1
- package/dist/ai/functions/readFiles.js +3 -3
- package/dist/ai/functions/readFiles.js.map +1 -1
- package/dist/ai/functions/readImagess.js +1 -2
- package/dist/ai/functions/readImagess.js.map +1 -1
- package/dist/ai/functions/shouldDrawImage.js +1 -2
- package/dist/ai/functions/shouldDrawImage.js.map +1 -1
- package/dist/ai/functions/typeWriter.js +1 -2
- package/dist/ai/functions/typeWriter.js.map +1 -1
- package/dist/ai/functions/validOptions.d.ts +2 -0
- package/dist/ai/functions/validOptions.d.ts.map +1 -1
- package/dist/ai/functions/validOptions.js +5 -1
- package/dist/ai/functions/validOptions.js.map +1 -1
- package/dist/ai/modals-chat/Gemini-flash.js +3 -5
- package/dist/ai/modals-chat/Gemini-flash.js.map +1 -1
- package/dist/ai/modals-chat/Gemini-pro.js +3 -5
- package/dist/ai/modals-chat/Gemini-pro.js.map +1 -1
- package/dist/ai/modals-chat/apexChat.js +1 -2
- package/dist/ai/modals-chat/apexChat.js.map +1 -1
- package/dist/ai/modals-chat/bard.d.ts.map +1 -1
- package/dist/ai/modals-chat/bard.js +24 -6
- package/dist/ai/modals-chat/bard.js.map +1 -1
- package/dist/ai/modals-chat/bing.d.ts.map +1 -1
- package/dist/ai/modals-chat/bing.js +24 -6
- package/dist/ai/modals-chat/bing.js.map +1 -1
- package/dist/ai/modals-chat/codellama.d.ts.map +1 -1
- package/dist/ai/modals-chat/codellama.js +23 -6
- package/dist/ai/modals-chat/codellama.js.map +1 -1
- package/dist/ai/modals-chat/facebook-ai.js +1 -2
- package/dist/ai/modals-chat/facebook-ai.js.map +1 -1
- package/dist/ai/modals-chat/geminiV2.d.ts.map +1 -1
- package/dist/ai/modals-chat/geminiV2.js +24 -6
- package/dist/ai/modals-chat/geminiV2.js.map +1 -1
- package/dist/ai/modals-chat/gemma.d.ts +1 -2
- package/dist/ai/modals-chat/gemma.d.ts.map +1 -1
- package/dist/ai/modals-chat/gemma.js +30 -41
- package/dist/ai/modals-chat/gemma.js.map +1 -1
- package/dist/ai/modals-chat/llama.d.ts.map +1 -1
- package/dist/ai/modals-chat/llama.js +24 -6
- package/dist/ai/modals-chat/llama.js.map +1 -1
- package/dist/ai/modals-chat/llamav2.d.ts +2 -0
- package/dist/ai/modals-chat/llamav2.d.ts.map +1 -0
- package/dist/ai/modals-chat/llamav2.js +43 -0
- package/dist/ai/modals-chat/llamav2.js.map +1 -0
- package/dist/ai/modals-chat/llamav3.d.ts +2 -0
- package/dist/ai/modals-chat/llamav3.d.ts.map +1 -0
- package/dist/ai/modals-chat/llamav3.js +43 -0
- package/dist/ai/modals-chat/llamav3.js.map +1 -0
- package/dist/ai/modals-chat/mixtral.d.ts.map +1 -1
- package/dist/ai/modals-chat/mixtral.js +24 -6
- package/dist/ai/modals-chat/mixtral.js.map +1 -1
- package/dist/ai/modals-chat/mixtralv2.d.ts +2 -0
- package/dist/ai/modals-chat/mixtralv2.d.ts.map +1 -0
- package/dist/ai/modals-chat/mixtralv2.js +43 -0
- package/dist/ai/modals-chat/mixtralv2.js.map +1 -0
- package/dist/ai/modals-chat/openChat.d.ts.map +1 -1
- package/dist/ai/modals-chat/openChat.js +24 -6
- package/dist/ai/modals-chat/openChat.js.map +1 -1
- package/dist/ai/modals-chat/starChat.js +1 -2
- package/dist/ai/modals-chat/starChat.js.map +1 -1
- package/dist/ai/modals-chat/v4.d.ts.map +1 -1
- package/dist/ai/modals-chat/v4.js +24 -6
- package/dist/ai/modals-chat/v4.js.map +1 -1
- package/dist/ai/modals-chat/whisper.d.ts +2 -0
- package/dist/ai/modals-chat/whisper.d.ts.map +1 -0
- package/dist/ai/modals-chat/whisper.js +101 -0
- package/dist/ai/modals-chat/whisper.js.map +1 -0
- package/dist/ai/modals-chat/yi-ai.js +1 -2
- package/dist/ai/modals-chat/yi-ai.js.map +1 -1
- package/dist/canvas/ApexPainter.d.ts +0 -1
- package/dist/canvas/ApexPainter.d.ts.map +1 -1
- package/dist/canvas/ApexPainter.js +5 -6
- package/dist/canvas/ApexPainter.js.map +1 -1
- package/dist/canvas/utils/bg.js +3 -4
- package/dist/canvas/utils/bg.js.map +1 -1
- package/dist/canvas/utils/charts.d.ts +0 -1
- package/dist/canvas/utils/charts.d.ts.map +1 -1
- package/dist/canvas/utils/charts.js +66 -75
- package/dist/canvas/utils/charts.js.map +1 -1
- package/dist/canvas/utils/circular.js +1 -2
- package/dist/canvas/utils/circular.js.map +1 -1
- package/dist/canvas/utils/conversion.d.ts +0 -1
- package/dist/canvas/utils/conversion.d.ts.map +1 -1
- package/dist/canvas/utils/conversion.js +5 -6
- package/dist/canvas/utils/conversion.js.map +1 -1
- package/dist/canvas/utils/customLines.js +1 -2
- package/dist/canvas/utils/customLines.js.map +1 -1
- package/dist/canvas/utils/general functions.d.ts +0 -1
- package/dist/canvas/utils/general functions.d.ts.map +1 -1
- package/dist/canvas/utils/general functions.js +12 -14
- package/dist/canvas/utils/general functions.js.map +1 -1
- package/dist/canvas/utils/imageProperties.js +7 -8
- package/dist/canvas/utils/imageProperties.js.map +1 -1
- package/dist/canvas/utils/radius.d.ts.map +1 -1
- package/dist/canvas/utils/radius.js +1 -2
- package/dist/canvas/utils/radius.js.map +1 -1
- package/dist/canvas/utils/textProperties.js +2 -3
- package/dist/canvas/utils/textProperties.js.map +1 -1
- package/dist/canvas/utils/types.d.ts +0 -2
- package/dist/canvas/utils/types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/lib/ai/ApexAI.ts +106 -12
- package/lib/ai/ApexModules.ts +88 -1
- package/lib/ai/ApexVoice.ts +0 -0
- package/lib/ai/functions/readFiles.ts +6 -4
- package/lib/ai/functions/validOptions.ts +7 -2
- package/lib/ai/modals-chat/bard.ts +20 -4
- package/lib/ai/modals-chat/bing.ts +20 -4
- package/lib/ai/modals-chat/codellama.ts +21 -6
- package/lib/ai/modals-chat/geminiV2.ts +20 -4
- package/lib/ai/modals-chat/gemma.ts +35 -0
- package/lib/ai/modals-chat/llama.ts +20 -4
- package/lib/ai/modals-chat/llamav2.ts +35 -0
- package/lib/ai/modals-chat/llamav3.ts +35 -0
- package/lib/ai/modals-chat/mixtral.ts +21 -4
- package/lib/ai/modals-chat/mixtralv2.ts +35 -0
- package/lib/ai/modals-chat/openChat.ts +20 -4
- package/lib/ai/modals-chat/v4.ts +20 -4
- package/lib/ai/modals-chat/whisper.ts +102 -0
- package/lib/canvas/ApexPainter.ts +3 -3
- package/lib/index.ts +3 -2
- package/package.json +7 -2
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import Groq from 'groq-sdk';
|
|
2
|
+
|
|
3
|
+
export async function gemma(prompt: string, API_KEY?: string): Promise<string> {
|
|
4
|
+
|
|
5
|
+
try {
|
|
6
|
+
const groq = new Groq({
|
|
7
|
+
apiKey: API_KEY || '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',
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const chatCompletion = await groq.chat.completions.create({
|
|
11
|
+
messages: [{ role: 'user', content: prompt }],
|
|
12
|
+
model: 'gemma-7b-it',
|
|
13
|
+
max_tokens: 8192
|
|
14
|
+
});
|
|
15
|
+
const response = chatCompletion.choices[0]?.message?.content || 'Rate limit'
|
|
16
|
+
|
|
17
|
+
return response;
|
|
18
|
+
} catch (err: any) {
|
|
19
|
+
if (err instanceof Groq.APIError) {
|
|
20
|
+
if (err.status === 400) {
|
|
21
|
+
return 'Bad request try again after a minute please.'
|
|
22
|
+
} else if (err.status === 429) {
|
|
23
|
+
return 'Rate limit try again after one minute or provide your own api-key.'
|
|
24
|
+
} else if (err.status === 401 || !err.status) {
|
|
25
|
+
throw new Error('Invalid Api-Key provided.')
|
|
26
|
+
} else {
|
|
27
|
+
console.error(err)
|
|
28
|
+
return "unknown error occurred."
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
31
|
+
console.error(err)
|
|
32
|
+
return "unknown error occurred."
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -17,11 +17,27 @@ export async function llamaChat({ API_KEY, prompt }: aiOptions): Promise<string>
|
|
|
17
17
|
return response.data.message;
|
|
18
18
|
} catch (e: any) {
|
|
19
19
|
if (e.response && e.response.data.message === 'Invalid API key.') {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
try {
|
|
21
|
+
const defaultResponse = await axios.post(`https://api.rnilaweera.lk/api/v1/user/llama`, { prompt }, {
|
|
22
|
+
headers: { Authorization: `Bearer rsnai_SbLbFcwdT2h2KoYet2LS0F34` },
|
|
23
|
+
});
|
|
24
|
+
return defaultResponse.data.message;
|
|
25
|
+
} catch (err) {
|
|
26
|
+
console.log(err);
|
|
27
|
+
return 'An error occurred while using the default API key.';
|
|
28
|
+
}
|
|
29
|
+
} else if (e.response && e.response.status === 500) {
|
|
30
|
+
try {
|
|
31
|
+
const defaultResponse = await axios.post(`https://api.rnilaweera.lk/api/v1/user/llama`, { prompt }, {
|
|
32
|
+
headers: { Authorization: `Bearer rsnai_lvIch9Z7apBHqfXYqOiXwzm7` },
|
|
33
|
+
});
|
|
34
|
+
return defaultResponse.data.message;
|
|
35
|
+
} catch (err) {
|
|
36
|
+
console.log(err);
|
|
37
|
+
return 'An error occurred while using the backup API key.';
|
|
38
|
+
}
|
|
24
39
|
} else {
|
|
40
|
+
console.log(e);
|
|
25
41
|
return 'The API is on cooldown for 50 seconds.';
|
|
26
42
|
}
|
|
27
43
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import Groq from 'groq-sdk';
|
|
2
|
+
|
|
3
|
+
export async function llama2(prompt: string, API_KEY?: string): Promise<string> {
|
|
4
|
+
|
|
5
|
+
try {
|
|
6
|
+
const groq = new Groq({
|
|
7
|
+
apiKey: API_KEY || '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',
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const chatCompletion = await groq.chat.completions.create({
|
|
11
|
+
messages: [{ role: 'user', content: prompt }],
|
|
12
|
+
model: 'llama3-70b-8192',
|
|
13
|
+
max_tokens: 8192
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const response = chatCompletion.choices[0]?.message?.content || 'Rate limit'
|
|
17
|
+
return response;
|
|
18
|
+
} catch (err: any) {
|
|
19
|
+
if (err instanceof Groq.APIError) {
|
|
20
|
+
if (err.status === 400) {
|
|
21
|
+
return 'Bad request try again after a minute please.'
|
|
22
|
+
} else if (err.status === 429) {
|
|
23
|
+
return 'Rate limit try again after one minute or provide your own api-key.'
|
|
24
|
+
} else if (err.status === 401 || !err.status) {
|
|
25
|
+
throw new Error('Invalid Api-Key provided.')
|
|
26
|
+
} else {
|
|
27
|
+
console.error(err)
|
|
28
|
+
return "unknown error occurred."
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
31
|
+
console.error(err)
|
|
32
|
+
return 'unknown error occurred.'
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import Groq from 'groq-sdk';
|
|
2
|
+
|
|
3
|
+
export async function llama3(prompt: string, API_KEY?: string): Promise<string> {
|
|
4
|
+
|
|
5
|
+
try {
|
|
6
|
+
const groq = new Groq({
|
|
7
|
+
apiKey: API_KEY || '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',
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const chatCompletion = await groq.chat.completions.create({
|
|
11
|
+
messages: [{ role: 'user', content: prompt }],
|
|
12
|
+
model: 'llama3-8b-8192',
|
|
13
|
+
max_tokens: 8192
|
|
14
|
+
});
|
|
15
|
+
const response = chatCompletion.choices[0]?.message?.content || 'Rate limit'
|
|
16
|
+
|
|
17
|
+
return response;
|
|
18
|
+
} catch (err: any) {
|
|
19
|
+
if (err instanceof Groq.APIError) {
|
|
20
|
+
if (err.status === 400) {
|
|
21
|
+
return 'Bad request try again after a minute please.'
|
|
22
|
+
} else if (err.status === 429) {
|
|
23
|
+
return 'Rate limit try again after one minute or provide your own api-key.'
|
|
24
|
+
} else if (err.status === 401 || !err.status) {
|
|
25
|
+
throw new Error('Invalid Api-Key provided.')
|
|
26
|
+
} else {
|
|
27
|
+
console.error(err)
|
|
28
|
+
return "unknown error occurred."
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
31
|
+
console.error(err)
|
|
32
|
+
return "unknown error occurred."
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -17,12 +17,29 @@ export async function mixtral({ API_KEY, prompt }: aiOptions): Promise<string> {
|
|
|
17
17
|
return response.data.message;
|
|
18
18
|
} catch (e: any) {
|
|
19
19
|
if (e.response && e.response.data.message === 'Invalid API key.') {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
try {
|
|
21
|
+
const defaultResponse = await axios.post(`https://api.rnilaweera.lk/api/v1/user/mixtral`, { prompt }, {
|
|
22
|
+
headers: { Authorization: `Bearer rsnai_SbLbFcwdT2h2KoYet2LS0F34` },
|
|
23
|
+
});
|
|
24
|
+
return defaultResponse.data.message;
|
|
25
|
+
} catch (err) {
|
|
26
|
+
console.log(err);
|
|
27
|
+
return 'An error occurred while using the default API key.';
|
|
28
|
+
}
|
|
29
|
+
} else if (e.response && e.response.status === 500) {
|
|
30
|
+
try {
|
|
31
|
+
const defaultResponse = await axios.post(`https://api.rnilaweera.lk/api/v1/user/mixtral`, { prompt }, {
|
|
32
|
+
headers: { Authorization: `Bearer rsnai_lvIch9Z7apBHqfXYqOiXwzm7` },
|
|
33
|
+
});
|
|
34
|
+
return defaultResponse.data.message;
|
|
35
|
+
} catch (err) {
|
|
36
|
+
console.log(err);
|
|
37
|
+
return 'An error occurred while using the backup API key.';
|
|
38
|
+
}
|
|
24
39
|
} else {
|
|
40
|
+
console.log(e);
|
|
25
41
|
return 'The API is on cooldown for 50 seconds.';
|
|
26
42
|
}
|
|
27
43
|
}
|
|
28
44
|
}
|
|
45
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import Groq from 'groq-sdk';
|
|
2
|
+
|
|
3
|
+
export async function mixtral2(prompt: string, API_KEY?: string): Promise<string> {
|
|
4
|
+
|
|
5
|
+
try {
|
|
6
|
+
const groq = new Groq({
|
|
7
|
+
apiKey: API_KEY || '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',
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const chatCompletion = await groq.chat.completions.create({
|
|
11
|
+
messages: [{ role: 'user', content: prompt }],
|
|
12
|
+
model: 'mixtral-8x7b-32768',
|
|
13
|
+
max_tokens: 8192
|
|
14
|
+
});
|
|
15
|
+
const response = chatCompletion.choices[0]?.message?.content || 'Rate limit'
|
|
16
|
+
|
|
17
|
+
return response;
|
|
18
|
+
} catch (err: any) {
|
|
19
|
+
if (err instanceof Groq.APIError) {
|
|
20
|
+
if (err.status === 400) {
|
|
21
|
+
return 'Bad request try again after a minute please.'
|
|
22
|
+
} else if (err.status === 429) {
|
|
23
|
+
return 'Rate limit try again after one minute or provide your own api-key.'
|
|
24
|
+
} else if (err.status === 401 || !err.status) {
|
|
25
|
+
throw new Error('Invalid Api-Key provided.')
|
|
26
|
+
} else {
|
|
27
|
+
console.error(err)
|
|
28
|
+
return "unknown error occurred."
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
31
|
+
console.error(err)
|
|
32
|
+
return "unknown error occurred."
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -17,11 +17,27 @@ export async function openChat({ API_KEY, prompt }: aiOptions): Promise<string>
|
|
|
17
17
|
return response.data.message;
|
|
18
18
|
} catch (e: any) {
|
|
19
19
|
if (e.response && e.response.data.message === 'Invalid API key.') {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
try {
|
|
21
|
+
const defaultResponse = await axios.post(`https://api.rnilaweera.lk/api/v1/user/openchat`, { prompt }, {
|
|
22
|
+
headers: { Authorization: `Bearer rsnai_SbLbFcwdT2h2KoYet2LS0F34` },
|
|
23
|
+
});
|
|
24
|
+
return defaultResponse.data.message;
|
|
25
|
+
} catch (err) {
|
|
26
|
+
console.log(err);
|
|
27
|
+
return 'An error occurred while using the default API key.';
|
|
28
|
+
}
|
|
29
|
+
} else if (e.response && e.response.status === 500) {
|
|
30
|
+
try {
|
|
31
|
+
const defaultResponse = await axios.post(`https://api.rnilaweera.lk/api/v1/user/openchat`, { prompt }, {
|
|
32
|
+
headers: { Authorization: `Bearer rsnai_lvIch9Z7apBHqfXYqOiXwzm7` },
|
|
33
|
+
});
|
|
34
|
+
return defaultResponse.data.message;
|
|
35
|
+
} catch (err) {
|
|
36
|
+
console.log(err);
|
|
37
|
+
return 'An error occurred while using the backup API key.';
|
|
38
|
+
}
|
|
24
39
|
} else {
|
|
40
|
+
console.log(e);
|
|
25
41
|
return 'The API is on cooldown for 50 seconds.';
|
|
26
42
|
}
|
|
27
43
|
}
|
package/lib/ai/modals-chat/v4.ts
CHANGED
|
@@ -17,11 +17,27 @@ export async function v4({ API_KEY, prompt }: aiOptions): Promise<string> {
|
|
|
17
17
|
return response.data.message;
|
|
18
18
|
} catch (e: any) {
|
|
19
19
|
if (e.response && e.response.data.message === 'Invalid API key.') {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
try {
|
|
21
|
+
const defaultResponse = await axios.post(`https://api.rnilaweera.lk/api/v1/user/gpt4`, { prompt }, {
|
|
22
|
+
headers: { Authorization: `Bearer rsnai_SbLbFcwdT2h2KoYet2LS0F34` },
|
|
23
|
+
});
|
|
24
|
+
return defaultResponse.data.message;
|
|
25
|
+
} catch (err) {
|
|
26
|
+
console.log(err);
|
|
27
|
+
return 'An error occurred while using the default API key.';
|
|
28
|
+
}
|
|
29
|
+
} else if (e.response && e.response.status === 500) {
|
|
30
|
+
try {
|
|
31
|
+
const defaultResponse = await axios.post(`https://api.rnilaweera.lk/api/v1/user/gpt4`, { prompt }, {
|
|
32
|
+
headers: { Authorization: `Bearer rsnai_lvIch9Z7apBHqfXYqOiXwzm7` },
|
|
33
|
+
});
|
|
34
|
+
return defaultResponse.data.message;
|
|
35
|
+
} catch (err) {
|
|
36
|
+
console.log(err);
|
|
37
|
+
return 'An error occurred while using the backup API key.';
|
|
38
|
+
}
|
|
24
39
|
} else {
|
|
40
|
+
console.log(e);
|
|
25
41
|
return 'The API is on cooldown for 50 seconds.';
|
|
26
42
|
}
|
|
27
43
|
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import Groq from 'groq-sdk';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { URL } from 'url';
|
|
5
|
+
import https from 'https';
|
|
6
|
+
|
|
7
|
+
function getFileSize(filePath: string): number {
|
|
8
|
+
const stats = fs.statSync(filePath);
|
|
9
|
+
return stats.size;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async function createReadableStream(filepathOrUrl: string): Promise<NodeJS.ReadableStream | string> {
|
|
13
|
+
const maxFileSizeBytes = 25 * 1024 * 1024; // 25MB in bytes
|
|
14
|
+
|
|
15
|
+
if (filepathOrUrl.startsWith('http')) {
|
|
16
|
+
const parsedUrl = new URL(filepathOrUrl);
|
|
17
|
+
const fileExtension = path.extname(parsedUrl.pathname);
|
|
18
|
+
const tempFilePath = `temp-file-${Date.now()}${fileExtension}`;
|
|
19
|
+
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
const file = fs.createWriteStream(tempFilePath);
|
|
22
|
+
|
|
23
|
+
https.get(filepathOrUrl, (response) => {
|
|
24
|
+
let fileSize = 0;
|
|
25
|
+
|
|
26
|
+
response.on('data', (chunk) => {
|
|
27
|
+
fileSize += chunk.length;
|
|
28
|
+
if (fileSize > maxFileSizeBytes) {
|
|
29
|
+
file.close();
|
|
30
|
+
fs.unlink(tempFilePath, () => {
|
|
31
|
+
resolve('File size exceeds the limit (25MB)');
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// @ts-ignore: Ignore type checking for this line
|
|
37
|
+
response.pipe(file);
|
|
38
|
+
|
|
39
|
+
file.on('finish', () => {
|
|
40
|
+
file.close(() => {
|
|
41
|
+
if (fileSize <= maxFileSizeBytes) {
|
|
42
|
+
// @ts-ignore: Ignore type checking for this line
|
|
43
|
+
resolve(fs.createReadStream(tempFilePath));
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}).on('error', (err) => {
|
|
48
|
+
fs.unlink(tempFilePath, () => {
|
|
49
|
+
reject(err);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
} else {
|
|
54
|
+
const fileSize = getFileSize(filepathOrUrl);
|
|
55
|
+
if (fileSize > maxFileSizeBytes) {
|
|
56
|
+
return 'File size exceeds the limit (25MB)';
|
|
57
|
+
}
|
|
58
|
+
// @ts-ignore: Ignore type checking for this line
|
|
59
|
+
return fs.createReadStream(filepathOrUrl);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export async function whisper(prompt: string, filepath: string, lang?: string, API_KEY?: string) {
|
|
64
|
+
try {
|
|
65
|
+
const groq = new Groq({
|
|
66
|
+
apiKey: API_KEY || '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',
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const fileStream = await createReadableStream(filepath);
|
|
70
|
+
|
|
71
|
+
if (typeof fileStream === 'string') {
|
|
72
|
+
return fileStream;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const transcription = await groq.audio.transcriptions.create({
|
|
76
|
+
// @ts-ignore: Ignore type checking for this line
|
|
77
|
+
file: fileStream,
|
|
78
|
+
model: "whisper-large-v3",
|
|
79
|
+
prompt: prompt,
|
|
80
|
+
temperature: 1,
|
|
81
|
+
language: lang || 'eng',
|
|
82
|
+
response_format: "verbose_json",
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
return transcription.text;
|
|
86
|
+
} catch (err: any) {
|
|
87
|
+
if (err instanceof Groq.APIError) {
|
|
88
|
+
if (err.status === 400) {
|
|
89
|
+
return 'Bad request, try again after a minute please.';
|
|
90
|
+
} else if (err.status === 429) {
|
|
91
|
+
return 'Rate limit, try again after one minute or provide your own api-key.';
|
|
92
|
+
} else if (err.status === 401 || !err.status) {
|
|
93
|
+
return 'Invalid Api-Key provided.';
|
|
94
|
+
} else {
|
|
95
|
+
console.error(err);
|
|
96
|
+
return "Unknown error occurred.";
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
console.error(err);
|
|
100
|
+
return 'Unknown error occurred.';
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -173,9 +173,9 @@ export class ApexPainter {
|
|
|
173
173
|
return canvas;
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
function createOutputStream(outputFile: any) {
|
|
176
|
+
function createOutputStream(outputFile: any): fs.WriteStream {
|
|
177
177
|
return fs.createWriteStream(outputFile);
|
|
178
|
-
|
|
178
|
+
}
|
|
179
179
|
|
|
180
180
|
function createBufferStream(): Writable & { getBuffer: () => Buffer } {
|
|
181
181
|
const bufferStream = new PassThrough();
|
|
@@ -190,7 +190,6 @@ export class ApexPainter {
|
|
|
190
190
|
return Buffer.concat(chunks);
|
|
191
191
|
};
|
|
192
192
|
|
|
193
|
-
console.log(`buffer get: ${{customBufferStream}}`)
|
|
194
193
|
return customBufferStream;
|
|
195
194
|
}
|
|
196
195
|
|
|
@@ -344,6 +343,7 @@ export class ApexPainter {
|
|
|
344
343
|
? createOutputStream(options.outputFile)
|
|
345
344
|
: createBufferStream();
|
|
346
345
|
|
|
346
|
+
// @ts-ignore: Ignore type checking for this line
|
|
347
347
|
encoder.createReadStream().pipe(outputStream);
|
|
348
348
|
|
|
349
349
|
encoder.start();
|
package/lib/index.ts
CHANGED
|
@@ -30,6 +30,7 @@ fetch("https://registry.npmjs.com/-/v1/search?text=apexify.js")
|
|
|
30
30
|
|
|
31
31
|
import { ApexAI, ApexChat, ApexImagine, ApexPainter } from "./utils";
|
|
32
32
|
import { validOptions } from "./ai/functions/validOptions";
|
|
33
|
+
export * from './canvas/utils/utils';
|
|
33
34
|
export * from './canvas/utils/types';
|
|
34
|
-
|
|
35
|
-
export
|
|
35
|
+
|
|
36
|
+
export { ApexPainter, ApexAI, ApexImagine, ApexChat, validOptions };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apexify.js",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.6",
|
|
4
4
|
"description": "Ai and Canvas library. Supports typescript and javascript",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -79,6 +79,10 @@
|
|
|
79
79
|
"voice",
|
|
80
80
|
"ai",
|
|
81
81
|
"chat bot",
|
|
82
|
+
"speech recognition",
|
|
83
|
+
"voice message",
|
|
84
|
+
"trained ai",
|
|
85
|
+
"trained model",
|
|
82
86
|
"image",
|
|
83
87
|
"ai generator",
|
|
84
88
|
"image generator",
|
|
@@ -157,7 +161,8 @@
|
|
|
157
161
|
"@napi-rs/canvas": "^0.1.51",
|
|
158
162
|
"api": "^6.1.1",
|
|
159
163
|
"gifencoder": "^2.0.1",
|
|
160
|
-
"
|
|
164
|
+
"groq-sdk": "^0.5.0",
|
|
165
|
+
"hercai": "^12.3.1",
|
|
161
166
|
"imgur": "^2.4.2",
|
|
162
167
|
"jimp": "^0.3.11",
|
|
163
168
|
"pdf-parse": "^1.1.1",
|