apexify.js 4.4.35 → 4.5.0

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 (216) hide show
  1. package/README.md +26 -199
  2. package/dist/ai/ApexAI.d.ts +18 -5
  3. package/dist/ai/ApexAI.d.ts.map +1 -1
  4. package/dist/ai/ApexAI.js +33 -170
  5. package/dist/ai/ApexAI.js.map +1 -1
  6. package/dist/ai/ApexModules.d.ts.map +1 -1
  7. package/dist/ai/ApexModules.js +37 -125
  8. package/dist/ai/ApexModules.js.map +1 -1
  9. package/dist/ai/functions/draw.d.ts +6 -1
  10. package/dist/ai/functions/draw.d.ts.map +1 -1
  11. package/dist/ai/functions/draw.js +18 -59
  12. package/dist/ai/functions/draw.js.map +1 -1
  13. package/dist/ai/functions/generateVoiceResponse.d.ts +6 -1
  14. package/dist/ai/functions/generateVoiceResponse.d.ts.map +1 -1
  15. package/dist/ai/functions/generateVoiceResponse.js +2 -2
  16. package/dist/ai/functions/generateVoiceResponse.js.map +1 -1
  17. package/dist/ai/functions/validOptions.d.ts +11 -4
  18. package/dist/ai/functions/validOptions.d.ts.map +1 -1
  19. package/dist/ai/functions/validOptions.js +15 -14
  20. package/dist/ai/functions/validOptions.js.map +1 -1
  21. package/dist/ai/modals-chat/electronHub/imageModels.d.ts +7 -0
  22. package/dist/ai/modals-chat/electronHub/imageModels.d.ts.map +1 -0
  23. package/dist/ai/modals-chat/electronHub/imageModels.js +28 -0
  24. package/dist/ai/modals-chat/electronHub/imageModels.js.map +1 -0
  25. package/dist/ai/modals-chat/freesedgpt/cartoon.d.ts +2 -0
  26. package/dist/ai/modals-chat/freesedgpt/cartoon.d.ts.map +1 -0
  27. package/dist/ai/modals-chat/freesedgpt/cartoon.js +26 -0
  28. package/dist/ai/modals-chat/freesedgpt/cartoon.js.map +1 -0
  29. package/dist/ai/modals-chat/freesedgpt/chat.d.ts +5 -0
  30. package/dist/ai/modals-chat/freesedgpt/chat.d.ts.map +1 -0
  31. package/dist/ai/modals-chat/freesedgpt/chat.js +30 -0
  32. package/dist/ai/modals-chat/freesedgpt/chat.js.map +1 -0
  33. package/dist/ai/modals-chat/freesedgpt/flux.d.ts +2 -0
  34. package/dist/ai/modals-chat/freesedgpt/flux.d.ts.map +1 -0
  35. package/dist/ai/modals-chat/freesedgpt/flux.js +26 -0
  36. package/dist/ai/modals-chat/freesedgpt/flux.js.map +1 -0
  37. package/dist/ai/modals-chat/gemini/Gemini-flash.d.ts.map +1 -0
  38. package/dist/ai/modals-chat/{Gemini-flash.js → gemini/Gemini-flash.js} +2 -2
  39. package/dist/ai/modals-chat/gemini/Gemini-flash.js.map +1 -0
  40. package/dist/ai/modals-chat/gemini/Gemini-pro.d.ts.map +1 -0
  41. package/dist/ai/modals-chat/{Gemini-pro.js → gemini/Gemini-pro.js} +2 -2
  42. package/dist/ai/modals-chat/gemini/Gemini-pro.js.map +1 -0
  43. package/dist/ai/modals-chat/gemini/config.d.ts.map +1 -0
  44. package/dist/ai/modals-chat/gemini/config.js.map +1 -0
  45. package/dist/ai/modals-chat/gemini/geminiFast.d.ts.map +1 -0
  46. package/dist/ai/modals-chat/gemini/geminiFast.js.map +1 -0
  47. package/dist/ai/modals-chat/groq/chatgroq.d.ts +9 -0
  48. package/dist/ai/modals-chat/groq/chatgroq.d.ts.map +1 -0
  49. package/dist/ai/modals-chat/groq/chatgroq.js +58 -0
  50. package/dist/ai/modals-chat/groq/chatgroq.js.map +1 -0
  51. package/dist/ai/modals-chat/groq/imageAnalyzer.d.ts +8 -0
  52. package/dist/ai/modals-chat/groq/imageAnalyzer.d.ts.map +1 -0
  53. package/dist/ai/modals-chat/groq/imageAnalyzer.js +64 -0
  54. package/dist/ai/modals-chat/groq/imageAnalyzer.js.map +1 -0
  55. package/dist/ai/modals-chat/groq/whisper.d.ts.map +1 -0
  56. package/dist/ai/modals-chat/{whisper.js → groq/whisper.js} +2 -2
  57. package/dist/ai/modals-chat/groq/whisper.js.map +1 -0
  58. package/dist/ai/modals-chat/hercai/chatModals.d.ts +7 -0
  59. package/dist/ai/modals-chat/hercai/chatModals.d.ts.map +1 -0
  60. package/dist/ai/modals-chat/hercai/chatModals.js +23 -0
  61. package/dist/ai/modals-chat/hercai/chatModals.js.map +1 -0
  62. package/dist/ai/modals-chat/hercai/chatModels.d.ts +7 -0
  63. package/dist/ai/modals-chat/hercai/chatModels.d.ts.map +1 -0
  64. package/dist/ai/modals-chat/hercai/chatModels.js +23 -0
  65. package/dist/ai/modals-chat/hercai/chatModels.js.map +1 -0
  66. package/dist/ai/modals-chat/others/otherModels.d.ts +7 -0
  67. package/dist/ai/modals-chat/others/otherModels.d.ts.map +1 -0
  68. package/dist/ai/modals-chat/others/otherModels.js +88 -0
  69. package/dist/ai/modals-chat/others/otherModels.js.map +1 -0
  70. package/dist/ai/modals-chat/rsn/rsnChat.d.ts +8 -0
  71. package/dist/ai/modals-chat/rsn/rsnChat.d.ts.map +1 -0
  72. package/dist/ai/modals-chat/{bing.js → rsn/rsnChat.js} +22 -8
  73. package/dist/ai/modals-chat/rsn/rsnChat.js.map +1 -0
  74. package/dist/ai/modals-images/cartoon.js +1 -1
  75. package/dist/ai/modals-images/cartoon.js.map +1 -1
  76. package/dist/ai/modals-images/flux.js +1 -1
  77. package/dist/ai/modals-images/flux.js.map +1 -1
  78. package/dist/ai/utils.d.ts +4 -7
  79. package/dist/ai/utils.d.ts.map +1 -1
  80. package/dist/ai/utils.js +6 -12
  81. package/dist/ai/utils.js.map +1 -1
  82. package/dist/index.d.ts +11 -6
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +6 -3
  85. package/dist/index.js.map +1 -1
  86. package/lib/ai/ApexAI.ts +92 -189
  87. package/lib/ai/ApexModules.ts +43 -135
  88. package/lib/ai/functions/draw.ts +24 -68
  89. package/lib/ai/functions/generateVoiceResponse.ts +3 -2
  90. package/lib/ai/functions/validOptions.ts +23 -22
  91. package/lib/ai/modals-chat/electronHub/imageModels.ts +26 -0
  92. package/lib/ai/{modals-images → modals-chat/freesedgpt}/cartoon.ts +3 -3
  93. package/lib/ai/modals-chat/freesedgpt/chat.ts +31 -0
  94. package/lib/ai/{modals-images → modals-chat/freesedgpt}/flux.ts +3 -3
  95. package/lib/ai/modals-chat/{Gemini-flash.ts → gemini/Gemini-flash.ts} +2 -2
  96. package/lib/ai/modals-chat/{Gemini-pro.ts → gemini/Gemini-pro.ts} +2 -2
  97. package/lib/ai/modals-chat/groq/chatgroq.ts +68 -0
  98. package/lib/ai/modals-chat/groq/imageAnalyzer.ts +68 -0
  99. package/lib/ai/modals-chat/{whisper.ts → groq/whisper.ts} +2 -2
  100. package/lib/ai/modals-chat/hercai/chatModels.ts +20 -0
  101. package/lib/ai/modals-chat/others/otherModels.ts +99 -0
  102. package/lib/ai/modals-chat/{mixtral.ts → rsn/rsnChat.ts} +26 -8
  103. package/lib/ai/utils.ts +7 -12
  104. package/lib/index.ts +5 -3
  105. package/package.json +1 -1
  106. package/dist/ai/functions/imageAnalysis.d.ts +0 -2
  107. package/dist/ai/functions/imageAnalysis.d.ts.map +0 -1
  108. package/dist/ai/functions/imageAnalysis.js +0 -45
  109. package/dist/ai/functions/imageAnalysis.js.map +0 -1
  110. package/dist/ai/functions/readImagess.d.ts +0 -2
  111. package/dist/ai/functions/readImagess.d.ts.map +0 -1
  112. package/dist/ai/functions/readImagess.js +0 -45
  113. package/dist/ai/functions/readImagess.js.map +0 -1
  114. package/dist/ai/modals-chat/Gemini-flash.d.ts.map +0 -1
  115. package/dist/ai/modals-chat/Gemini-flash.js.map +0 -1
  116. package/dist/ai/modals-chat/Gemini-pro.d.ts.map +0 -1
  117. package/dist/ai/modals-chat/Gemini-pro.js.map +0 -1
  118. package/dist/ai/modals-chat/apexChat.d.ts +0 -2
  119. package/dist/ai/modals-chat/apexChat.d.ts.map +0 -1
  120. package/dist/ai/modals-chat/apexChat.js +0 -32
  121. package/dist/ai/modals-chat/apexChat.js.map +0 -1
  122. package/dist/ai/modals-chat/bard.d.ts +0 -7
  123. package/dist/ai/modals-chat/bard.d.ts.map +0 -1
  124. package/dist/ai/modals-chat/bard.js +0 -48
  125. package/dist/ai/modals-chat/bard.js.map +0 -1
  126. package/dist/ai/modals-chat/bing.d.ts +0 -7
  127. package/dist/ai/modals-chat/bing.d.ts.map +0 -1
  128. package/dist/ai/modals-chat/bing.js.map +0 -1
  129. package/dist/ai/modals-chat/codellama.d.ts +0 -7
  130. package/dist/ai/modals-chat/codellama.d.ts.map +0 -1
  131. package/dist/ai/modals-chat/codellama.js +0 -48
  132. package/dist/ai/modals-chat/codellama.js.map +0 -1
  133. package/dist/ai/modals-chat/config.d.ts.map +0 -1
  134. package/dist/ai/modals-chat/config.js.map +0 -1
  135. package/dist/ai/modals-chat/facebook-ai.d.ts +0 -2
  136. package/dist/ai/modals-chat/facebook-ai.d.ts.map +0 -1
  137. package/dist/ai/modals-chat/facebook-ai.js +0 -20
  138. package/dist/ai/modals-chat/facebook-ai.js.map +0 -1
  139. package/dist/ai/modals-chat/geminiFast.d.ts.map +0 -1
  140. package/dist/ai/modals-chat/geminiFast.js.map +0 -1
  141. package/dist/ai/modals-chat/geminiV2.d.ts +0 -7
  142. package/dist/ai/modals-chat/geminiV2.d.ts.map +0 -1
  143. package/dist/ai/modals-chat/geminiV2.js +0 -48
  144. package/dist/ai/modals-chat/geminiV2.js.map +0 -1
  145. package/dist/ai/modals-chat/gemma.d.ts +0 -2
  146. package/dist/ai/modals-chat/gemma.d.ts.map +0 -1
  147. package/dist/ai/modals-chat/gemma.js +0 -43
  148. package/dist/ai/modals-chat/gemma.js.map +0 -1
  149. package/dist/ai/modals-chat/llama.d.ts +0 -7
  150. package/dist/ai/modals-chat/llama.d.ts.map +0 -1
  151. package/dist/ai/modals-chat/llama.js +0 -48
  152. package/dist/ai/modals-chat/llama.js.map +0 -1
  153. package/dist/ai/modals-chat/llamav2.d.ts +0 -2
  154. package/dist/ai/modals-chat/llamav2.d.ts.map +0 -1
  155. package/dist/ai/modals-chat/llamav2.js +0 -43
  156. package/dist/ai/modals-chat/llamav2.js.map +0 -1
  157. package/dist/ai/modals-chat/llamav3.d.ts +0 -2
  158. package/dist/ai/modals-chat/llamav3.d.ts.map +0 -1
  159. package/dist/ai/modals-chat/llamav3.js +0 -43
  160. package/dist/ai/modals-chat/llamav3.js.map +0 -1
  161. package/dist/ai/modals-chat/mixtral.d.ts +0 -7
  162. package/dist/ai/modals-chat/mixtral.d.ts.map +0 -1
  163. package/dist/ai/modals-chat/mixtral.js +0 -48
  164. package/dist/ai/modals-chat/mixtral.js.map +0 -1
  165. package/dist/ai/modals-chat/mixtralv2.d.ts +0 -2
  166. package/dist/ai/modals-chat/mixtralv2.d.ts.map +0 -1
  167. package/dist/ai/modals-chat/mixtralv2.js +0 -43
  168. package/dist/ai/modals-chat/mixtralv2.js.map +0 -1
  169. package/dist/ai/modals-chat/modals.d.ts +0 -8
  170. package/dist/ai/modals-chat/modals.d.ts.map +0 -1
  171. package/dist/ai/modals-chat/modals.js +0 -16
  172. package/dist/ai/modals-chat/modals.js.map +0 -1
  173. package/dist/ai/modals-chat/openChat.d.ts +0 -7
  174. package/dist/ai/modals-chat/openChat.d.ts.map +0 -1
  175. package/dist/ai/modals-chat/openChat.js +0 -48
  176. package/dist/ai/modals-chat/openChat.js.map +0 -1
  177. package/dist/ai/modals-chat/starChat.d.ts +0 -2
  178. package/dist/ai/modals-chat/starChat.d.ts.map +0 -1
  179. package/dist/ai/modals-chat/starChat.js +0 -31
  180. package/dist/ai/modals-chat/starChat.js.map +0 -1
  181. package/dist/ai/modals-chat/v4.d.ts +0 -7
  182. package/dist/ai/modals-chat/v4.d.ts.map +0 -1
  183. package/dist/ai/modals-chat/v4.js +0 -48
  184. package/dist/ai/modals-chat/v4.js.map +0 -1
  185. package/dist/ai/modals-chat/whisper.d.ts.map +0 -1
  186. package/dist/ai/modals-chat/whisper.js.map +0 -1
  187. package/dist/ai/modals-chat/yi-ai.d.ts +0 -2
  188. package/dist/ai/modals-chat/yi-ai.d.ts.map +0 -1
  189. package/dist/ai/modals-chat/yi-ai.js +0 -40
  190. package/dist/ai/modals-chat/yi-ai.js.map +0 -1
  191. package/lib/ai/functions/imageAnalysis.ts +0 -41
  192. package/lib/ai/modals-chat/apexChat.ts +0 -31
  193. package/lib/ai/modals-chat/bard.ts +0 -44
  194. package/lib/ai/modals-chat/bing.ts +0 -44
  195. package/lib/ai/modals-chat/codellama.ts +0 -44
  196. package/lib/ai/modals-chat/facebook-ai.ts +0 -14
  197. package/lib/ai/modals-chat/geminiV2.ts +0 -44
  198. package/lib/ai/modals-chat/gemma.ts +0 -35
  199. package/lib/ai/modals-chat/llama.ts +0 -44
  200. package/lib/ai/modals-chat/llamav2.ts +0 -35
  201. package/lib/ai/modals-chat/llamav3.ts +0 -35
  202. package/lib/ai/modals-chat/mixtralv2.ts +0 -35
  203. package/lib/ai/modals-chat/modals.ts +0 -8
  204. package/lib/ai/modals-chat/openChat.ts +0 -44
  205. package/lib/ai/modals-chat/starChat.ts +0 -31
  206. package/lib/ai/modals-chat/v4.ts +0 -44
  207. package/lib/ai/modals-chat/yi-ai.ts +0 -40
  208. /package/dist/ai/modals-chat/{Gemini-flash.d.ts → gemini/Gemini-flash.d.ts} +0 -0
  209. /package/dist/ai/modals-chat/{Gemini-pro.d.ts → gemini/Gemini-pro.d.ts} +0 -0
  210. /package/dist/ai/modals-chat/{config.d.ts → gemini/config.d.ts} +0 -0
  211. /package/dist/ai/modals-chat/{config.js → gemini/config.js} +0 -0
  212. /package/dist/ai/modals-chat/{geminiFast.d.ts → gemini/geminiFast.d.ts} +0 -0
  213. /package/dist/ai/modals-chat/{geminiFast.js → gemini/geminiFast.js} +0 -0
  214. /package/dist/ai/modals-chat/{whisper.d.ts → groq/whisper.d.ts} +0 -0
  215. /package/lib/ai/modals-chat/{config.ts → gemini/config.ts} +0 -0
  216. /package/lib/ai/modals-chat/{geminiFast.ts → gemini/geminiFast.ts} +0 -0
@@ -1,35 +0,0 @@
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
- }
@@ -1,35 +0,0 @@
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
- }
@@ -1,35 +0,0 @@
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
- }
@@ -1,8 +0,0 @@
1
- import { yi_34b } from "./yi-ai";
2
- import { starChat } from "./starChat";
3
- import { apexai } from "./apexChat";
4
- import { geminiFlash } from "./Gemini-flash";
5
- import { geminiPro } from "./Gemini-pro";
6
- import { facebook_ai } from "./facebook-ai";
7
-
8
- export { geminiFlash, yi_34b, facebook_ai, geminiPro, apexai, starChat };
@@ -1,44 +0,0 @@
1
- import axios, { AxiosResponse } from 'axios';
2
-
3
- interface aiOptions {
4
- API_KEY?: string | null;
5
- prompt: string;
6
- }
7
-
8
- export async function openChat({ 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/openchat`, 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/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
- }
39
- } else {
40
- console.log(e);
41
- return 'The API is on cooldown for 50 seconds.';
42
- }
43
- }
44
- }
@@ -1,31 +0,0 @@
1
- import axios from 'axios';
2
-
3
- export async function starChat(prompt: string) {
4
- const messages = [{ "role": "assistant", "content": `${prompt}` }];
5
- try {
6
- const response = await axios.post('https://api-inference.huggingface.co/models/HuggingFaceH4/starchat2-15b-v0.1', {
7
- inputs: JSON.stringify(messages),
8
- }, {
9
- headers: {
10
- 'Authorization': `Bearer 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`,
11
- },
12
- });
13
- const chatbotReply = response.data[0];
14
-
15
- let chatbotResponseText = chatbotReply.generated_text.replace(/^.*?\n.*?\n/, '');
16
-
17
- if (chatbotResponseText.startsWith('[' || '{')) {
18
- chatbotResponseText = JSON.parse(chatbotResponseText);
19
-
20
- chatbotResponseText = chatbotResponseText.join(' ');
21
- }
22
-
23
- return chatbotResponseText;
24
- }
25
- catch (error: any) {
26
- console.error('Error fetching response:', error.message);
27
- return 'Please wait i am on cooldown.';
28
- }
29
- }
30
-
31
-
@@ -1,44 +0,0 @@
1
- import axios, { AxiosResponse } from 'axios';
2
-
3
- interface aiOptions {
4
- API_KEY?: string | null;
5
- prompt: string;
6
- }
7
-
8
- export async function v4({ 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/gpt4`, 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/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
- }
39
- } else {
40
- console.log(e);
41
- return 'The API is on cooldown for 50 seconds.';
42
- }
43
- }
44
- }
@@ -1,40 +0,0 @@
1
- import axios from 'axios';
2
-
3
- export async function yi_34b(prompt: string) {
4
- try {
5
- const messages = [
6
- { "role": "user", "content": prompt }
7
- ];
8
-
9
- const formattedMessages = messages.map(message => `[${message.role}] ${message.content}`).join('\n');
10
-
11
- const response = await axios.post(
12
- `https://api-inference.huggingface.co/models/01-ai/Yi-1.5-34B-Chat`,
13
- { inputs: formattedMessages },
14
- {
15
- headers: {
16
- 'Authorization': `Bearer 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`,
17
- 'Content-Type': 'application/json'
18
- }
19
- }
20
- );
21
-
22
- const generatedText = response.data[0].generated_text;
23
- const botIndex = generatedText.indexOf('[bot]', generatedText.indexOf('[user]'));
24
-
25
- if (botIndex !== -1) {
26
- let botResponse = generatedText.substring(botIndex);
27
- const nextBotIndex = botResponse.indexOf('[bot]', 1);
28
- const nextUserIndex = botResponse.indexOf('[user]', 1);
29
- const endIndex = Math.min(nextBotIndex !== -1 ? nextBotIndex : botResponse.length, nextUserIndex !== -1 ? nextUserIndex : botResponse.length);
30
- botResponse = botResponse.substring(0, endIndex);
31
- botResponse = botResponse.substring(botResponse.indexOf('[bot]') + 5).trim();
32
- return botResponse;
33
- } else {
34
- return generatedText;
35
- }
36
- } catch (error: any) {
37
- console.error('Error:', error.response.data);
38
- return 'Please wait, I am on cooldown.';
39
- }
40
- }