apexify.js 4.2.3 → 4.2.5

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 (158) hide show
  1. package/README.md +5 -4
  2. package/dist/ai/ApexAI.d.ts +2 -0
  3. package/dist/ai/ApexAI.d.ts.map +1 -1
  4. package/dist/ai/ApexAI.js +31 -22
  5. package/dist/ai/ApexAI.js.map +1 -1
  6. package/dist/ai/ApexModules.d.ts +10 -1
  7. package/dist/ai/ApexModules.d.ts.map +1 -1
  8. package/dist/ai/ApexModules.js +96 -3
  9. package/dist/ai/ApexModules.js.map +1 -1
  10. package/dist/ai/buttons/drawMenu.js +1 -2
  11. package/dist/ai/buttons/drawMenu.js.map +1 -1
  12. package/dist/ai/buttons/tools.js +1 -2
  13. package/dist/ai/buttons/tools.js.map +1 -1
  14. package/dist/ai/functions/chunkString.js +1 -2
  15. package/dist/ai/functions/chunkString.js.map +1 -1
  16. package/dist/ai/functions/draw.js +9 -11
  17. package/dist/ai/functions/draw.js.map +1 -1
  18. package/dist/ai/functions/generateVoiceResponse.js +1 -2
  19. package/dist/ai/functions/generateVoiceResponse.js.map +1 -1
  20. package/dist/ai/functions/imageReader.js +1 -2
  21. package/dist/ai/functions/imageReader.js.map +1 -1
  22. package/dist/ai/functions/readFiles.d.ts.map +1 -1
  23. package/dist/ai/functions/readFiles.js +3 -3
  24. package/dist/ai/functions/readFiles.js.map +1 -1
  25. package/dist/ai/functions/readImagess.js +1 -2
  26. package/dist/ai/functions/readImagess.js.map +1 -1
  27. package/dist/ai/functions/shouldDrawImage.js +1 -2
  28. package/dist/ai/functions/shouldDrawImage.js.map +1 -1
  29. package/dist/ai/functions/typeWriter.js +1 -2
  30. package/dist/ai/functions/typeWriter.js.map +1 -1
  31. package/dist/ai/functions/validOptions.d.ts +2 -0
  32. package/dist/ai/functions/validOptions.d.ts.map +1 -1
  33. package/dist/ai/functions/validOptions.js +5 -1
  34. package/dist/ai/functions/validOptions.js.map +1 -1
  35. package/dist/ai/modals-chat/Gemini-flash.js +3 -5
  36. package/dist/ai/modals-chat/Gemini-flash.js.map +1 -1
  37. package/dist/ai/modals-chat/Gemini-pro.js +3 -5
  38. package/dist/ai/modals-chat/Gemini-pro.js.map +1 -1
  39. package/dist/ai/modals-chat/apexChat.js +1 -2
  40. package/dist/ai/modals-chat/apexChat.js.map +1 -1
  41. package/dist/ai/modals-chat/bard.d.ts +7 -0
  42. package/dist/ai/modals-chat/bard.d.ts.map +1 -0
  43. package/dist/ai/modals-chat/bard.js +48 -0
  44. package/dist/ai/modals-chat/bard.js.map +1 -0
  45. package/dist/ai/modals-chat/bing.d.ts +7 -0
  46. package/dist/ai/modals-chat/bing.d.ts.map +1 -0
  47. package/dist/ai/modals-chat/bing.js +48 -0
  48. package/dist/ai/modals-chat/bing.js.map +1 -0
  49. package/dist/ai/modals-chat/codellama.d.ts +7 -0
  50. package/dist/ai/modals-chat/codellama.d.ts.map +1 -0
  51. package/dist/ai/modals-chat/codellama.js +48 -0
  52. package/dist/ai/modals-chat/codellama.js.map +1 -0
  53. package/dist/ai/modals-chat/facebook-ai.js +1 -2
  54. package/dist/ai/modals-chat/facebook-ai.js.map +1 -1
  55. package/dist/ai/modals-chat/geminiV2.d.ts +7 -0
  56. package/dist/ai/modals-chat/geminiV2.d.ts.map +1 -0
  57. package/dist/ai/modals-chat/geminiV2.js +48 -0
  58. package/dist/ai/modals-chat/geminiV2.js.map +1 -0
  59. package/dist/ai/modals-chat/gemma.d.ts +1 -2
  60. package/dist/ai/modals-chat/gemma.d.ts.map +1 -1
  61. package/dist/ai/modals-chat/gemma.js +30 -41
  62. package/dist/ai/modals-chat/gemma.js.map +1 -1
  63. package/dist/ai/modals-chat/llama.d.ts.map +1 -1
  64. package/dist/ai/modals-chat/llama.js +25 -7
  65. package/dist/ai/modals-chat/llama.js.map +1 -1
  66. package/dist/ai/modals-chat/llamav2.d.ts +2 -0
  67. package/dist/ai/modals-chat/llamav2.d.ts.map +1 -0
  68. package/dist/ai/modals-chat/llamav2.js +43 -0
  69. package/dist/ai/modals-chat/llamav2.js.map +1 -0
  70. package/dist/ai/modals-chat/llamav3.d.ts +2 -0
  71. package/dist/ai/modals-chat/llamav3.d.ts.map +1 -0
  72. package/dist/ai/modals-chat/llamav3.js +43 -0
  73. package/dist/ai/modals-chat/llamav3.js.map +1 -0
  74. package/dist/ai/modals-chat/mixtral.d.ts.map +1 -1
  75. package/dist/ai/modals-chat/mixtral.js +24 -6
  76. package/dist/ai/modals-chat/mixtral.js.map +1 -1
  77. package/dist/ai/modals-chat/mixtralv2.d.ts +2 -0
  78. package/dist/ai/modals-chat/mixtralv2.d.ts.map +1 -0
  79. package/dist/ai/modals-chat/mixtralv2.js +43 -0
  80. package/dist/ai/modals-chat/mixtralv2.js.map +1 -0
  81. package/dist/ai/modals-chat/openChat.d.ts.map +1 -1
  82. package/dist/ai/modals-chat/openChat.js +25 -7
  83. package/dist/ai/modals-chat/openChat.js.map +1 -1
  84. package/dist/ai/modals-chat/starChat.js +1 -2
  85. package/dist/ai/modals-chat/starChat.js.map +1 -1
  86. package/dist/ai/modals-chat/v4.d.ts.map +1 -1
  87. package/dist/ai/modals-chat/v4.js +24 -6
  88. package/dist/ai/modals-chat/v4.js.map +1 -1
  89. package/dist/ai/modals-chat/whisper.d.ts +2 -0
  90. package/dist/ai/modals-chat/whisper.d.ts.map +1 -0
  91. package/dist/ai/modals-chat/whisper.js +101 -0
  92. package/dist/ai/modals-chat/whisper.js.map +1 -0
  93. package/dist/ai/modals-chat/yi-ai.js +1 -2
  94. package/dist/ai/modals-chat/yi-ai.js.map +1 -1
  95. package/dist/canvas/ApexPainter.d.ts +4 -2
  96. package/dist/canvas/ApexPainter.d.ts.map +1 -1
  97. package/dist/canvas/ApexPainter.js +42 -12
  98. package/dist/canvas/ApexPainter.js.map +1 -1
  99. package/dist/canvas/utils/bg.js +3 -4
  100. package/dist/canvas/utils/bg.js.map +1 -1
  101. package/dist/canvas/utils/charts.d.ts +0 -1
  102. package/dist/canvas/utils/charts.d.ts.map +1 -1
  103. package/dist/canvas/utils/charts.js +66 -75
  104. package/dist/canvas/utils/charts.js.map +1 -1
  105. package/dist/canvas/utils/circular.js +1 -2
  106. package/dist/canvas/utils/circular.js.map +1 -1
  107. package/dist/canvas/utils/conversion.d.ts +6 -0
  108. package/dist/canvas/utils/conversion.d.ts.map +1 -0
  109. package/dist/canvas/utils/conversion.js +34 -0
  110. package/dist/canvas/utils/conversion.js.map +1 -0
  111. package/dist/canvas/utils/customLines.js +1 -2
  112. package/dist/canvas/utils/customLines.js.map +1 -1
  113. package/dist/canvas/utils/general functions.d.ts +0 -1
  114. package/dist/canvas/utils/general functions.d.ts.map +1 -1
  115. package/dist/canvas/utils/general functions.js +12 -14
  116. package/dist/canvas/utils/general functions.js.map +1 -1
  117. package/dist/canvas/utils/imageProperties.js +7 -8
  118. package/dist/canvas/utils/imageProperties.js.map +1 -1
  119. package/dist/canvas/utils/radius.d.ts.map +1 -1
  120. package/dist/canvas/utils/radius.js +1 -2
  121. package/dist/canvas/utils/radius.js.map +1 -1
  122. package/dist/canvas/utils/textProperties.js +2 -3
  123. package/dist/canvas/utils/textProperties.js.map +1 -1
  124. package/dist/canvas/utils/types.d.ts +7 -2
  125. package/dist/canvas/utils/types.d.ts.map +1 -1
  126. package/dist/canvas/utils/types.js +4 -0
  127. package/dist/canvas/utils/types.js.map +1 -1
  128. package/dist/canvas/utils/utils.d.ts +3 -2
  129. package/dist/canvas/utils/utils.d.ts.map +1 -1
  130. package/dist/canvas/utils/utils.js +7 -1
  131. package/dist/canvas/utils/utils.js.map +1 -1
  132. package/dist/index.d.ts +2 -16
  133. package/dist/index.d.ts.map +1 -1
  134. package/dist/index.js +6 -3
  135. package/dist/index.js.map +1 -1
  136. package/lib/ai/ApexAI.ts +20 -10
  137. package/lib/ai/ApexModules.ts +104 -2
  138. package/lib/ai/functions/readFiles.ts +6 -4
  139. package/lib/ai/functions/validOptions.ts +7 -2
  140. package/lib/ai/modals-chat/bard.ts +44 -0
  141. package/lib/ai/modals-chat/bing.ts +44 -0
  142. package/lib/ai/modals-chat/codellama.ts +44 -0
  143. package/lib/ai/modals-chat/geminiV2.ts +44 -0
  144. package/lib/ai/modals-chat/gemma.ts +35 -0
  145. package/lib/ai/modals-chat/llama.ts +21 -5
  146. package/lib/ai/modals-chat/llamav2.ts +35 -0
  147. package/lib/ai/modals-chat/llamav3.ts +35 -0
  148. package/lib/ai/modals-chat/mixtral.ts +21 -4
  149. package/lib/ai/modals-chat/mixtralv2.ts +35 -0
  150. package/lib/ai/modals-chat/openChat.ts +21 -5
  151. package/lib/ai/modals-chat/v4.ts +20 -4
  152. package/lib/ai/modals-chat/whisper.ts +102 -0
  153. package/lib/canvas/ApexPainter.ts +51 -9
  154. package/lib/canvas/utils/conversion.ts +35 -0
  155. package/lib/canvas/utils/types.ts +9 -0
  156. package/lib/canvas/utils/utils.ts +8 -1
  157. package/lib/index.ts +4 -2
  158. package/package.json +9 -1
@@ -0,0 +1,44 @@
1
+ import axios, { AxiosResponse } from 'axios';
2
+
3
+ interface aiOptions {
4
+ API_KEY?: string | null;
5
+ prompt: string;
6
+ }
7
+
8
+ export async function gemini_v2({ API_KEY, prompt }: aiOptions): Promise<string> {
9
+ const apiKey: string = API_KEY || 'rsnai_SbLbFcwdT2h2KoYet2LS0F34';
10
+
11
+ try {
12
+ const payload = { prompt: prompt };
13
+ const response: AxiosResponse = await axios.post(`https://api.rnilaweera.lk/api/v1/user/gemini`, payload, {
14
+ headers: { Authorization: `Bearer ${apiKey}` },
15
+ });
16
+
17
+ return response.data.message;
18
+ } catch (e: any) {
19
+ if (e.response && e.response.data.message === 'Invalid API key.') {
20
+ try {
21
+ const defaultResponse = await axios.post(`https://api.rnilaweera.lk/api/v1/user/gemini`, { 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/gemini`, { 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
+ }
39
+ } else {
40
+ console.log(e);
41
+ return 'The API is on cooldown for 50 seconds.';
42
+ }
43
+ }
44
+ }
@@ -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
+ }
@@ -10,18 +10,34 @@ export async function llamaChat({ API_KEY, prompt }: aiOptions): Promise<string>
10
10
 
11
11
  try {
12
12
  const payload = { prompt: prompt };
13
- const response: AxiosResponse = await axios.post(`https://api.rnilaweera.lk/api/v1/user/codellama`, payload, {
13
+ const response: AxiosResponse = await axios.post(`https://api.rnilaweera.lk/api/v1/user/llama`, payload, {
14
14
  headers: { Authorization: `Bearer ${apiKey}` },
15
15
  });
16
16
 
17
17
  return response.data.message;
18
18
  } catch (e: any) {
19
19
  if (e.response && e.response.data.message === 'Invalid API key.') {
20
- const defaultResponse = await axios.post(`https://api.rnilaweera.lk/api/v1/user/codellama`, { prompt }, {
21
- headers: { Authorization: `Bearer rsnai_SbLbFcwdT2h2KoYet2LS0F34` },
22
- });
23
- return defaultResponse.data.message;
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
- const defaultResponse = await axios.post(`https://api.rnilaweera.lk/api/v1/user/mixtral`, { prompt }, {
21
- headers: { Authorization: `Bearer rsnai_SbLbFcwdT2h2KoYet2LS0F34` },
22
- });
23
- return defaultResponse.data.message;
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
+ }
@@ -10,18 +10,34 @@ export async function openChat({ API_KEY, prompt }: aiOptions): Promise<string>
10
10
 
11
11
  try {
12
12
  const payload = { prompt: prompt };
13
- const response: AxiosResponse = await axios.post(`https://api.rnilaweera.lk/api/v1/user/openChat`, payload, {
13
+ const response: AxiosResponse = await axios.post(`https://api.rnilaweera.lk/api/v1/user/openchat`, payload, {
14
14
  headers: { Authorization: `Bearer ${apiKey}` },
15
15
  });
16
16
 
17
17
  return response.data.message;
18
18
  } catch (e: any) {
19
19
  if (e.response && e.response.data.message === 'Invalid API key.') {
20
- const defaultResponse = await axios.post(`https://api.rnilaweera.lk/api/v1/user/openChat`, { prompt }, {
21
- headers: { Authorization: `Bearer rsnai_SbLbFcwdT2h2KoYet2LS0F34` },
22
- });
23
- return defaultResponse.data.message;
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
  }
@@ -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
- const defaultResponse = await axios.post(`https://api.rnilaweera.lk/api/v1/user/gpt4`, { prompt }, {
21
- headers: { Authorization: `Bearer rsnai_SbLbFcwdT2h2KoYet2LS0F34` },
22
- });
23
- return defaultResponse.data.message;
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
+ }
@@ -1,14 +1,25 @@
1
1
  import { createCanvas, loadImage, GlobalFonts } from "@napi-rs/canvas";
2
- import path from 'path';
3
- import GIFEncoder from 'gifencoder';
4
- import { PassThrough, Writable} from 'stream'
5
- import fs from 'fs';
6
- import { CanvasConfig, TextObject, ImageProperties, ImageObject, GIFOptions, GIFResults, CustomOptions, cropOptions,
2
+ import GIFEncoder from "gifencoder";
3
+ import { PassThrough, Writable} from "stream";
4
+ import fs from "fs";
5
+ import path from "path";
6
+ import { OutputFormat, CanvasConfig, TextObject, ImageProperties, ImageObject, GIFOptions, GIFResults, CustomOptions, cropOptions,
7
7
  drawBackgroundGradient, drawBackgroundColor, customBackground, circularBorder, radiusBorder, customLines,
8
8
  applyRotation, applyStroke, applyShadow, imageRadius, drawShape, drawText,
9
- converter, resizingImg, applyColorFilters, imgEffects, verticalBarChart, pieChart, lineChart, cropInner, cropOuter, bgRemoval, detectColors, removeColor } from "./utils/utils";
9
+ converter, resizingImg, applyColorFilters, imgEffects, verticalBarChart, pieChart, lineChart, cropInner, cropOuter, bgRemoval, detectColors, removeColor,
10
+ dataURL,
11
+ base64,
12
+ arrayBuffer,
13
+ blob,
14
+ url
15
+ } from "./utils/utils";
10
16
 
11
17
  export class ApexPainter {
18
+ private format?: OutputFormat;
19
+
20
+ constructor({ type }: OutputFormat = { type: 'buffer' }) {
21
+ this.format = { type: type || 'buffer' };
22
+ }
12
23
 
13
24
  async createCanvas(canvas: CanvasConfig): Promise<Buffer> {
14
25
  let canvasWidth: number = canvas.width || 500;
@@ -16,7 +27,10 @@ export class ApexPainter {
16
27
  let borderRadius: number | string = canvas.borderRadius || 0;
17
28
 
18
29
  if (canvas.customBg) {
30
+
19
31
  try {
32
+
33
+ if (canvas.customBg.startsWith('https' || 'http')) {
20
34
  const response = await fetch(canvas.customBg);
21
35
  if (!response.ok) {
22
36
  throw new Error("Failed to fetch background image.");
@@ -25,6 +39,13 @@ export class ApexPainter {
25
39
  const image = await loadImage(Buffer.from(buffer));
26
40
  canvasWidth = image.width;
27
41
  canvasHeight = image.height;
42
+ } else {
43
+ const bgPath = path.join(process.cwd(), canvas.customBg);
44
+ const image = await loadImage(bgPath);
45
+ canvasWidth = image.width;
46
+ canvasHeight = image.height;
47
+ }
48
+
28
49
  } catch (error) {
29
50
  console.error('Error loading custom background image:', error);
30
51
  }
@@ -152,9 +173,9 @@ export class ApexPainter {
152
173
  return canvas;
153
174
  }
154
175
 
155
- function createOutputStream(outputFile: any) {
176
+ function createOutputStream(outputFile: any): fs.WriteStream {
156
177
  return fs.createWriteStream(outputFile);
157
- }
178
+ }
158
179
 
159
180
  function createBufferStream(): Writable & { getBuffer: () => Buffer } {
160
181
  const bufferStream = new PassThrough();
@@ -169,7 +190,6 @@ export class ApexPainter {
169
190
  return Buffer.concat(chunks);
170
191
  };
171
192
 
172
- console.log(`buffer get: ${{customBufferStream}}`)
173
193
  return customBufferStream;
174
194
  }
175
195
 
@@ -323,6 +343,7 @@ export class ApexPainter {
323
343
  ? createOutputStream(options.outputFile)
324
344
  : createBufferStream();
325
345
 
346
+ // @ts-ignore: Ignore type checking for this line
326
347
  encoder.createReadStream().pipe(outputStream);
327
348
 
328
349
  encoder.start();
@@ -563,4 +584,25 @@ export class ApexPainter {
563
584
  }
564
585
  return true
565
586
  }
587
+
588
+ public async outPut(results: any): Promise< void | Buffer | string | Blob | Object | HTMLCanvasElement> {
589
+
590
+ const formatType: string = this.format?.type || 'buffer';
591
+ switch (formatType) {
592
+ case 'buffer':
593
+ return results;
594
+ case 'url':
595
+ return await url(results);
596
+ case 'dataURL':
597
+ return dataURL(results);
598
+ case 'blob':
599
+ return blob(results);
600
+ case 'base64':
601
+ return base64(results);
602
+ case 'arraybuffer':
603
+ return arrayBuffer(results);
604
+ default:
605
+ throw new Error('Unsupported format');
606
+ }
607
+ }
566
608
  }
@@ -0,0 +1,35 @@
1
+ import { createCanvas, loadImage, Canvas, Image } from "@napi-rs/canvas"; // Adjust imports based on the actual library
2
+ import {ImgurClient } from "imgur";
3
+
4
+
5
+ export async function url(buffer: Buffer) {
6
+ const client = new ImgurClient({
7
+ clientId: "cd66e7c46e15b4e",
8
+ clientSecret: "14a6adf67597a7b2db5e535a09c24843470fc70b",
9
+ accessToken: "ad06eacb7c7228d8f482d2db20f490d649f58e52",
10
+ refreshToken: "57fd64eeca315fcd25584fbbde91950bf17a7f5e"
11
+ });
12
+
13
+ const response = await client.upload({
14
+ image: base64(buffer),
15
+ type: 'base64',
16
+ });
17
+
18
+ return response.data.link;
19
+ }
20
+
21
+ export function dataURL(buffer: any): string {
22
+ return `data:image/png;base64,${Buffer.from(buffer).toString('base64')}`;
23
+ }
24
+
25
+ export function blob(buffer: any): Blob {
26
+ return new Blob([buffer], { type: 'image/png' });
27
+ }
28
+
29
+ export function base64(buffer: any): string {
30
+ return Buffer.from(buffer).toString('base64');
31
+ }
32
+
33
+ export function arrayBuffer(buffer: any): ArrayBuffer {
34
+ return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
35
+ }
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Configuration option to decide the outputformate from ApexPainter
3
+ * @param {type} default - 'buffer', other formates: url, blob, base64, dataURL, arraybuffer.
4
+ */
5
+
6
+ export interface OutputFormat {
7
+ type?: 'buffer' | 'url' | 'blob' | 'base64' | 'dataURL' | 'arraybuffer';
8
+ }
9
+
1
10
  /**
2
11
  * Configuration options for the canvas.
3
12
  * @param {number} width - The width of the canvas.
@@ -10,7 +10,7 @@
10
10
 
11
11
 
12
12
 
13
- import { CanvasConfig, ImageProperties, TextObject, ImageObject, GIFOptions, GIFResults, CustomOptions, cropOptions } from "./types";
13
+ import { OutputFormat, CanvasConfig, ImageProperties, TextObject, ImageObject, GIFOptions, GIFResults, CustomOptions, cropOptions } from "./types";
14
14
  import { radiusBorder } from "./radius";
15
15
  import { circularBorder } from "./circular";
16
16
  import { drawBackgroundColor, drawBackgroundGradient, customBackground } from "./bg";
@@ -19,8 +19,15 @@ import { drawText, WrappedText } from "./textProperties";
19
19
  import { loadImages, resizingImg, converter, applyColorFilters, imgEffects, cropOuter, cropInner, detectColors, removeColor, bgRemoval } from './general functions';
20
20
  import { customLines } from "./customLines";
21
21
  import { verticalBarChart, pieChart, lineChart } from './charts'
22
+ import { url, arrayBuffer, base64, dataURL, blob } from "./conversion";
22
23
 
23
24
  export {
25
+ url,
26
+ OutputFormat,
27
+ arrayBuffer,
28
+ base64,
29
+ dataURL,
30
+ blob,
24
31
  CanvasConfig,
25
32
  ImageProperties,
26
33
  TextObject,
package/lib/index.ts CHANGED
@@ -30,5 +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 { ApexPainter, ApexAI, ApexImagine, ApexChat, validOptions };
34
- export default { ApexPainter, ApexAI, ApexImagine, ApexChat, validOptions };
33
+ export * from './canvas/utils/utils';
34
+ export * from './canvas/utils/types';
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",
3
+ "version": "4.2.5",
4
4
  "description": "Ai and Canvas library. Supports typescript and javascript",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -15,6 +15,8 @@
15
15
  "dist"
16
16
  ],
17
17
  "keywords": [
18
+ "apexify",
19
+ "apexify.js",
18
20
  "manipulation",
19
21
  "gemini-pro",
20
22
  "gemini",
@@ -77,6 +79,10 @@
77
79
  "voice",
78
80
  "ai",
79
81
  "chat bot",
82
+ "speech recognition",
83
+ "voice message",
84
+ "trained ai",
85
+ "trained model",
80
86
  "image",
81
87
  "ai generator",
82
88
  "image generator",
@@ -155,7 +161,9 @@
155
161
  "@napi-rs/canvas": "^0.1.51",
156
162
  "api": "^6.1.1",
157
163
  "gifencoder": "^2.0.1",
164
+ "groq-sdk": "^0.5.0",
158
165
  "hercai": "^12.2.0",
166
+ "imgur": "^2.4.2",
159
167
  "jimp": "^0.3.11",
160
168
  "pdf-parse": "^1.1.1",
161
169
  "rsnchat": "^4.0.1",