apexify.js 4.5.55 → 4.5.57

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 (238) hide show
  1. package/dist/cjs/ai/ApexAI.d.ts +1 -164
  2. package/dist/cjs/ai/ApexAI.d.ts.map +1 -1
  3. package/dist/cjs/ai/ApexAI.js +190 -373
  4. package/dist/cjs/ai/ApexAI.js.map +1 -1
  5. package/dist/cjs/ai/ApexModules.d.ts.map +1 -1
  6. package/dist/cjs/ai/ApexModules.js +6 -18
  7. package/dist/cjs/ai/ApexModules.js.map +1 -1
  8. package/dist/cjs/ai/functions/draw.d.ts.map +1 -1
  9. package/dist/cjs/ai/functions/draw.js +6 -6
  10. package/dist/cjs/ai/functions/draw.js.map +1 -1
  11. package/dist/cjs/ai/utils.d.ts +1 -4
  12. package/dist/cjs/ai/utils.d.ts.map +1 -1
  13. package/dist/cjs/ai/utils.js +1 -7
  14. package/dist/cjs/ai/utils.js.map +1 -1
  15. package/dist/cjs/canvas/ApexPainter.d.ts +24 -15
  16. package/dist/cjs/canvas/ApexPainter.d.ts.map +1 -1
  17. package/dist/cjs/canvas/ApexPainter.js +78 -56
  18. package/dist/cjs/canvas/ApexPainter.js.map +1 -1
  19. package/dist/cjs/canvas/utils/Background/bg.d.ts +24 -0
  20. package/dist/cjs/canvas/utils/Background/bg.d.ts.map +1 -0
  21. package/dist/{esm/canvas/utils → cjs/canvas/utils/Background}/bg.js +27 -52
  22. package/dist/cjs/canvas/utils/Background/bg.js.map +1 -0
  23. package/dist/cjs/canvas/utils/Background/circular.d.ts +3 -0
  24. package/dist/cjs/canvas/utils/Background/circular.d.ts.map +1 -0
  25. package/dist/{esm/canvas/utils → cjs/canvas/utils/Background}/circular.js +0 -8
  26. package/dist/cjs/canvas/utils/{circular.js.map → Background/circular.js.map} +1 -1
  27. package/dist/cjs/canvas/utils/Background/radius.d.ts +18 -0
  28. package/dist/cjs/canvas/utils/Background/radius.d.ts.map +1 -0
  29. package/dist/cjs/canvas/utils/Background/radius.js +104 -0
  30. package/dist/cjs/canvas/utils/Background/radius.js.map +1 -0
  31. package/dist/cjs/canvas/utils/{charts.d.ts → Charts/charts.d.ts} +1 -1
  32. package/dist/cjs/canvas/utils/Charts/charts.d.ts.map +1 -0
  33. package/dist/cjs/canvas/utils/Charts/charts.js.map +1 -0
  34. package/dist/cjs/canvas/utils/Custom/customLines.d.ts +3 -0
  35. package/dist/cjs/canvas/utils/Custom/customLines.d.ts.map +1 -0
  36. package/dist/cjs/canvas/utils/Custom/customLines.js.map +1 -0
  37. package/dist/cjs/canvas/utils/General/conversion.d.ts.map +1 -0
  38. package/dist/cjs/canvas/utils/General/conversion.js.map +1 -0
  39. package/dist/cjs/canvas/utils/{general functions.d.ts → General/general functions.d.ts } +18 -4
  40. package/dist/cjs/canvas/utils/General/general functions.d.ts.map +1 -0
  41. package/dist/{esm/canvas/utils → cjs/canvas/utils/General}/general functions.js +89 -58
  42. package/dist/cjs/canvas/utils/General/general functions.js.map +1 -0
  43. package/dist/cjs/canvas/utils/Image/imageProperties.d.ts +121 -0
  44. package/dist/cjs/canvas/utils/Image/imageProperties.d.ts.map +1 -0
  45. package/dist/cjs/canvas/utils/Image/imageProperties.js +623 -0
  46. package/dist/cjs/canvas/utils/Image/imageProperties.js.map +1 -0
  47. package/dist/{esm/canvas/utils → cjs/canvas/utils/Texts}/textProperties.d.ts +1 -1
  48. package/dist/cjs/canvas/utils/Texts/textProperties.d.ts.map +1 -0
  49. package/dist/cjs/canvas/utils/Texts/textProperties.js.map +1 -0
  50. package/dist/cjs/canvas/utils/types.d.ts +74 -3
  51. package/dist/cjs/canvas/utils/types.d.ts.map +1 -1
  52. package/dist/cjs/canvas/utils/types.js.map +1 -1
  53. package/dist/cjs/canvas/utils/utils.d.ts +11 -11
  54. package/dist/cjs/canvas/utils/utils.d.ts.map +1 -1
  55. package/dist/cjs/canvas/utils/utils.js +12 -10
  56. package/dist/cjs/canvas/utils/utils.js.map +1 -1
  57. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  58. package/dist/esm/ai/ApexAI.d.ts +1 -164
  59. package/dist/esm/ai/ApexAI.d.ts.map +1 -1
  60. package/dist/esm/ai/ApexAI.js +190 -373
  61. package/dist/esm/ai/ApexAI.js.map +1 -1
  62. package/dist/esm/ai/ApexModules.d.ts.map +1 -1
  63. package/dist/esm/ai/ApexModules.js +6 -18
  64. package/dist/esm/ai/ApexModules.js.map +1 -1
  65. package/dist/esm/ai/functions/draw.d.ts.map +1 -1
  66. package/dist/esm/ai/functions/draw.js +6 -6
  67. package/dist/esm/ai/functions/draw.js.map +1 -1
  68. package/dist/esm/ai/utils.d.ts +1 -4
  69. package/dist/esm/ai/utils.d.ts.map +1 -1
  70. package/dist/esm/ai/utils.js +1 -7
  71. package/dist/esm/ai/utils.js.map +1 -1
  72. package/dist/esm/canvas/ApexPainter.d.ts +24 -15
  73. package/dist/esm/canvas/ApexPainter.d.ts.map +1 -1
  74. package/dist/esm/canvas/ApexPainter.js +78 -56
  75. package/dist/esm/canvas/ApexPainter.js.map +1 -1
  76. package/dist/esm/canvas/utils/Background/bg.d.ts +24 -0
  77. package/dist/esm/canvas/utils/Background/bg.d.ts.map +1 -0
  78. package/dist/{cjs/canvas/utils → esm/canvas/utils/Background}/bg.js +27 -52
  79. package/dist/esm/canvas/utils/Background/bg.js.map +1 -0
  80. package/dist/esm/canvas/utils/Background/circular.d.ts +3 -0
  81. package/dist/esm/canvas/utils/Background/circular.d.ts.map +1 -0
  82. package/dist/{cjs/canvas/utils → esm/canvas/utils/Background}/circular.js +0 -8
  83. package/dist/esm/canvas/utils/{circular.js.map → Background/circular.js.map} +1 -1
  84. package/dist/esm/canvas/utils/Background/radius.d.ts +18 -0
  85. package/dist/esm/canvas/utils/Background/radius.d.ts.map +1 -0
  86. package/dist/esm/canvas/utils/Background/radius.js +104 -0
  87. package/dist/esm/canvas/utils/Background/radius.js.map +1 -0
  88. package/dist/esm/canvas/utils/{charts.d.ts → Charts/charts.d.ts} +1 -1
  89. package/dist/esm/canvas/utils/Charts/charts.d.ts.map +1 -0
  90. package/dist/esm/canvas/utils/Charts/charts.js.map +1 -0
  91. package/dist/esm/canvas/utils/Custom/customLines.d.ts +3 -0
  92. package/dist/esm/canvas/utils/Custom/customLines.d.ts.map +1 -0
  93. package/dist/esm/canvas/utils/Custom/customLines.js.map +1 -0
  94. package/dist/esm/canvas/utils/General/conversion.d.ts.map +1 -0
  95. package/dist/esm/canvas/utils/General/conversion.js.map +1 -0
  96. package/dist/esm/canvas/utils/{general functions.d.ts → General/general functions.d.ts } +18 -4
  97. package/dist/esm/canvas/utils/General/general functions.d.ts.map +1 -0
  98. package/dist/{cjs/canvas/utils → esm/canvas/utils/General}/general functions.js +89 -58
  99. package/dist/esm/canvas/utils/General/general functions.js.map +1 -0
  100. package/dist/esm/canvas/utils/Image/imageProperties.d.ts +121 -0
  101. package/dist/esm/canvas/utils/Image/imageProperties.d.ts.map +1 -0
  102. package/dist/esm/canvas/utils/Image/imageProperties.js +623 -0
  103. package/dist/esm/canvas/utils/Image/imageProperties.js.map +1 -0
  104. package/dist/{cjs/canvas/utils → esm/canvas/utils/Texts}/textProperties.d.ts +1 -1
  105. package/dist/esm/canvas/utils/Texts/textProperties.d.ts.map +1 -0
  106. package/dist/esm/canvas/utils/Texts/textProperties.js.map +1 -0
  107. package/dist/esm/canvas/utils/types.d.ts +74 -3
  108. package/dist/esm/canvas/utils/types.d.ts.map +1 -1
  109. package/dist/esm/canvas/utils/types.js.map +1 -1
  110. package/dist/esm/canvas/utils/utils.d.ts +11 -11
  111. package/dist/esm/canvas/utils/utils.d.ts.map +1 -1
  112. package/dist/esm/canvas/utils/utils.js +12 -10
  113. package/dist/esm/canvas/utils/utils.js.map +1 -1
  114. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  115. package/lib/ai/ApexAI.ts +195 -697
  116. package/lib/ai/ApexModules.ts +6 -16
  117. package/lib/ai/functions/draw.ts +6 -8
  118. package/lib/ai/utils.ts +0 -6
  119. package/lib/canvas/ApexPainter.ts +185 -111
  120. package/lib/canvas/utils/Background/bg.ts +97 -0
  121. package/lib/canvas/utils/Background/circular.ts +17 -0
  122. package/lib/canvas/utils/Background/radius.ts +102 -0
  123. package/lib/canvas/utils/{charts.ts → Charts/charts.ts} +1 -1
  124. package/lib/canvas/utils/{customLines.ts → Custom/customLines.ts} +1 -1
  125. package/lib/canvas/utils/{general functions.ts → General/general functions.ts } +143 -121
  126. package/lib/canvas/utils/Image/imageProperties.ts +779 -0
  127. package/lib/canvas/utils/{textProperties.ts → Texts/textProperties.ts} +1 -1
  128. package/lib/canvas/utils/types.ts +63 -4
  129. package/lib/canvas/utils/utils.ts +15 -11
  130. package/package.json +1 -5
  131. package/dist/cjs/ai/functions/generateVoiceResponse.d.ts +0 -10
  132. package/dist/cjs/ai/functions/generateVoiceResponse.d.ts.map +0 -1
  133. package/dist/cjs/ai/functions/generateVoiceResponse.js +0 -161
  134. package/dist/cjs/ai/functions/generateVoiceResponse.js.map +0 -1
  135. package/dist/cjs/ai/modals-chat/gemini/Gemini-flash.d.ts +0 -13
  136. package/dist/cjs/ai/modals-chat/gemini/Gemini-flash.d.ts.map +0 -1
  137. package/dist/cjs/ai/modals-chat/gemini/Gemini-flash.js +0 -185
  138. package/dist/cjs/ai/modals-chat/gemini/Gemini-flash.js.map +0 -1
  139. package/dist/cjs/ai/modals-chat/gemini/Gemini-pro.d.ts +0 -13
  140. package/dist/cjs/ai/modals-chat/gemini/Gemini-pro.d.ts.map +0 -1
  141. package/dist/cjs/ai/modals-chat/gemini/Gemini-pro.js +0 -185
  142. package/dist/cjs/ai/modals-chat/gemini/Gemini-pro.js.map +0 -1
  143. package/dist/cjs/ai/modals-chat/gemini/config.d.ts +0 -5
  144. package/dist/cjs/ai/modals-chat/gemini/config.d.ts.map +0 -1
  145. package/dist/cjs/ai/modals-chat/gemini/config.js +0 -13
  146. package/dist/cjs/ai/modals-chat/gemini/config.js.map +0 -1
  147. package/dist/cjs/ai/modals-chat/gemini/geminiFast.d.ts +0 -15
  148. package/dist/cjs/ai/modals-chat/gemini/geminiFast.d.ts.map +0 -1
  149. package/dist/cjs/ai/modals-chat/gemini/geminiFast.js +0 -146
  150. package/dist/cjs/ai/modals-chat/gemini/geminiFast.js.map +0 -1
  151. package/dist/cjs/canvas/utils/bg.d.ts +0 -23
  152. package/dist/cjs/canvas/utils/bg.d.ts.map +0 -1
  153. package/dist/cjs/canvas/utils/bg.js.map +0 -1
  154. package/dist/cjs/canvas/utils/charts.d.ts.map +0 -1
  155. package/dist/cjs/canvas/utils/charts.js.map +0 -1
  156. package/dist/cjs/canvas/utils/circular.d.ts +0 -10
  157. package/dist/cjs/canvas/utils/circular.d.ts.map +0 -1
  158. package/dist/cjs/canvas/utils/conversion.d.ts.map +0 -1
  159. package/dist/cjs/canvas/utils/conversion.js.map +0 -1
  160. package/dist/cjs/canvas/utils/customLines.d.ts +0 -3
  161. package/dist/cjs/canvas/utils/customLines.d.ts.map +0 -1
  162. package/dist/cjs/canvas/utils/customLines.js.map +0 -1
  163. package/dist/cjs/canvas/utils/general functions.d.ts.map +0 -1
  164. package/dist/cjs/canvas/utils/general functions.js.map +0 -1
  165. package/dist/cjs/canvas/utils/imageProperties.d.ts +0 -62
  166. package/dist/cjs/canvas/utils/imageProperties.d.ts.map +0 -1
  167. package/dist/cjs/canvas/utils/imageProperties.js +0 -341
  168. package/dist/cjs/canvas/utils/imageProperties.js.map +0 -1
  169. package/dist/cjs/canvas/utils/radius.d.ts +0 -10
  170. package/dist/cjs/canvas/utils/radius.d.ts.map +0 -1
  171. package/dist/cjs/canvas/utils/radius.js +0 -30
  172. package/dist/cjs/canvas/utils/radius.js.map +0 -1
  173. package/dist/cjs/canvas/utils/textProperties.d.ts.map +0 -1
  174. package/dist/cjs/canvas/utils/textProperties.js.map +0 -1
  175. package/dist/esm/ai/functions/generateVoiceResponse.d.ts +0 -10
  176. package/dist/esm/ai/functions/generateVoiceResponse.d.ts.map +0 -1
  177. package/dist/esm/ai/functions/generateVoiceResponse.js +0 -161
  178. package/dist/esm/ai/functions/generateVoiceResponse.js.map +0 -1
  179. package/dist/esm/ai/modals-chat/gemini/Gemini-flash.d.ts +0 -13
  180. package/dist/esm/ai/modals-chat/gemini/Gemini-flash.d.ts.map +0 -1
  181. package/dist/esm/ai/modals-chat/gemini/Gemini-flash.js +0 -185
  182. package/dist/esm/ai/modals-chat/gemini/Gemini-flash.js.map +0 -1
  183. package/dist/esm/ai/modals-chat/gemini/Gemini-pro.d.ts +0 -13
  184. package/dist/esm/ai/modals-chat/gemini/Gemini-pro.d.ts.map +0 -1
  185. package/dist/esm/ai/modals-chat/gemini/Gemini-pro.js +0 -185
  186. package/dist/esm/ai/modals-chat/gemini/Gemini-pro.js.map +0 -1
  187. package/dist/esm/ai/modals-chat/gemini/config.d.ts +0 -5
  188. package/dist/esm/ai/modals-chat/gemini/config.d.ts.map +0 -1
  189. package/dist/esm/ai/modals-chat/gemini/config.js +0 -13
  190. package/dist/esm/ai/modals-chat/gemini/config.js.map +0 -1
  191. package/dist/esm/ai/modals-chat/gemini/geminiFast.d.ts +0 -15
  192. package/dist/esm/ai/modals-chat/gemini/geminiFast.d.ts.map +0 -1
  193. package/dist/esm/ai/modals-chat/gemini/geminiFast.js +0 -146
  194. package/dist/esm/ai/modals-chat/gemini/geminiFast.js.map +0 -1
  195. package/dist/esm/canvas/utils/bg.d.ts +0 -23
  196. package/dist/esm/canvas/utils/bg.d.ts.map +0 -1
  197. package/dist/esm/canvas/utils/bg.js.map +0 -1
  198. package/dist/esm/canvas/utils/charts.d.ts.map +0 -1
  199. package/dist/esm/canvas/utils/charts.js.map +0 -1
  200. package/dist/esm/canvas/utils/circular.d.ts +0 -10
  201. package/dist/esm/canvas/utils/circular.d.ts.map +0 -1
  202. package/dist/esm/canvas/utils/conversion.d.ts.map +0 -1
  203. package/dist/esm/canvas/utils/conversion.js.map +0 -1
  204. package/dist/esm/canvas/utils/customLines.d.ts +0 -3
  205. package/dist/esm/canvas/utils/customLines.d.ts.map +0 -1
  206. package/dist/esm/canvas/utils/customLines.js.map +0 -1
  207. package/dist/esm/canvas/utils/general functions.d.ts.map +0 -1
  208. package/dist/esm/canvas/utils/general functions.js.map +0 -1
  209. package/dist/esm/canvas/utils/imageProperties.d.ts +0 -62
  210. package/dist/esm/canvas/utils/imageProperties.d.ts.map +0 -1
  211. package/dist/esm/canvas/utils/imageProperties.js +0 -341
  212. package/dist/esm/canvas/utils/imageProperties.js.map +0 -1
  213. package/dist/esm/canvas/utils/radius.d.ts +0 -10
  214. package/dist/esm/canvas/utils/radius.d.ts.map +0 -1
  215. package/dist/esm/canvas/utils/radius.js +0 -30
  216. package/dist/esm/canvas/utils/radius.js.map +0 -1
  217. package/dist/esm/canvas/utils/textProperties.d.ts.map +0 -1
  218. package/dist/esm/canvas/utils/textProperties.js.map +0 -1
  219. package/lib/ai/functions/generateVoiceResponse.ts +0 -186
  220. package/lib/ai/modals-chat/gemini/Gemini-flash.ts +0 -200
  221. package/lib/ai/modals-chat/gemini/Gemini-pro.ts +0 -203
  222. package/lib/ai/modals-chat/gemini/config.ts +0 -11
  223. package/lib/ai/modals-chat/gemini/geminiFast.ts +0 -169
  224. package/lib/canvas/utils/bg.ts +0 -120
  225. package/lib/canvas/utils/circular.ts +0 -17
  226. package/lib/canvas/utils/imageProperties.ts +0 -418
  227. package/lib/canvas/utils/radius.ts +0 -26
  228. /package/dist/cjs/canvas/utils/{charts.js → Charts/charts.js} +0 -0
  229. /package/dist/cjs/canvas/utils/{customLines.js → Custom/customLines.js} +0 -0
  230. /package/dist/cjs/canvas/utils/{conversion.d.ts → General/conversion.d.ts} +0 -0
  231. /package/dist/cjs/canvas/utils/{conversion.js → General/conversion.js} +0 -0
  232. /package/dist/cjs/canvas/utils/{textProperties.js → Texts/textProperties.js} +0 -0
  233. /package/dist/esm/canvas/utils/{charts.js → Charts/charts.js} +0 -0
  234. /package/dist/esm/canvas/utils/{customLines.js → Custom/customLines.js} +0 -0
  235. /package/dist/esm/canvas/utils/{conversion.d.ts → General/conversion.d.ts} +0 -0
  236. /package/dist/esm/canvas/utils/{conversion.js → General/conversion.js} +0 -0
  237. /package/dist/esm/canvas/utils/{textProperties.js → Texts/textProperties.js} +0 -0
  238. /package/lib/canvas/utils/{conversion.ts → General/conversion.ts} +0 -0
@@ -1,200 +0,0 @@
1
- import { GoogleGenerativeAI, HarmCategory, HarmBlockThreshold } from "@google/generative-ai";
2
- import { converter } from "../../../canvas/utils/general functions";
3
- import { connect } from "verse.db";
4
- import config from './config';
5
- import axios from "axios";
6
- import path from 'path';
7
- import fs from 'fs';
8
- import { readFile } from "../../utils";
9
-
10
- export async function geminiFlash(message: { userId: string, serverName: string, serverId: string, channelName: string, attachment: any, db: boolean }, AI: { AiPersonality: string | null, userMsg: string, API_KEY: string | null }): Promise<any> {
11
-
12
- async function validateKey(apiKey: string) {
13
- try {
14
- const validateResponse = await axios.get(`https://generativelanguage.googleapis.com/v1beta/models?key=${apiKey}`);
15
- return validateResponse.status === 200;
16
- } catch (error) {
17
- console.error(`Error validating API key: ${apiKey}`, error);
18
- return false;
19
- }
20
- }
21
-
22
- async function processRequest(genAI: any): Promise<any> {
23
- let personalityString = '';
24
-
25
- if (AI.AiPersonality) {
26
- const personalityFilePath = path.join(process.cwd(), AI.AiPersonality);
27
- const personalityContent = fs.readFileSync(personalityFilePath, 'utf-8');
28
- personalityString = personalityContent.split('\n').join(' ');
29
- }
30
-
31
- const generationConfig = {
32
- maxOutputTokens: 1048576,
33
- };
34
-
35
- const safetySettings = [
36
- {
37
- category: HarmCategory.HARM_CATEGORY_HARASSMENT,
38
- threshold: HarmBlockThreshold.BLOCK_NONE,
39
- },
40
- {
41
- category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
42
- threshold: HarmBlockThreshold.BLOCK_NONE,
43
- },
44
- {
45
- category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
46
- threshold: HarmBlockThreshold.BLOCK_NONE,
47
- },
48
- {
49
- category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
50
- threshold: HarmBlockThreshold.BLOCK_NONE,
51
- },
52
- ];
53
-
54
-
55
- const systemInstruction = `${personalityString}\n And working on discord in serverName: ${message.serverName} at channelName: ${message.channelName} and responding to the userName: <@${message.userId}>`;
56
- const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash-latest", systemInstruction, generationConfig, safetySettings });
57
-
58
- const defaultHistory = [
59
- {
60
- role: "user",
61
- parts: [{ text: `Hey who are you?` }],
62
- },
63
- {
64
- role: "model",
65
- parts: [{ text: `I am an AI assistant built/developed/created by Apexify.js` }],
66
- },
67
- {
68
- role: "user",
69
- parts: [{ text: `You have chat Memory?` }],
70
- },
71
- {
72
- role: "model",
73
- parts: [{ text: `Yes, I save chat history for each user if it is enabled in my configuration otherwise no data being saved.` }],
74
- },
75
- {
76
- role: "user",
77
- parts: [{ text: `How is your data/memory/chat history managed?` }],
78
- },
79
- {
80
- role: "model",
81
- parts: [{ text: `It is managed by verse.db. A database used to manage JSON/SQL/YAML/SQON database with ease and supports schema/schemaless data.` }],
82
- }
83
- ];
84
-
85
- let historyData: any[] | undefined = undefined;
86
-
87
- let db: any;
88
- if (message.db) {
89
- db = new connect({ adapter: 'json', dataPath: `${message.serverId}_ChatHistory` });
90
- const data = await db.find(`${message.userId}_chatHistory`, { userId: message.userId });
91
- historyData = data.results?.history.slice(-100) || undefined;
92
- }
93
-
94
- const chat = model.startChat({
95
- history: historyData || defaultHistory,
96
- generationConfig
97
- });
98
-
99
- const imgURL = message.attachment?.url || null;
100
- let result: any;
101
-
102
- if (imgURL && message.attachment?.contentType?.startsWith("image/")) {
103
- const url = await urlToBase64(imgURL);
104
-
105
- result = await model.generateContent([AI.userMsg, {
106
- inlineData: {
107
- data: url,
108
- mimeType: message.attachment?.contentType
109
- }
110
- }]);
111
-
112
- } else if (message.attachment?.name.endsWith('.pdf')) {
113
- const pdfContent = await readFile(message.attachment?.url, 'pdf');
114
- AI.userMsg += `\n\n- This is the PDF file content:\n\n ${pdfContent}`;
115
- result = await chat.sendMessage(AI.userMsg);
116
- } else if (message.attachment?.name.endsWith('.txt')) {
117
- const txtContent = await readFile(message.attachment?.url, 'txt');
118
- AI.userMsg += `\n\n- This is the .txt file content:\n\n ${txtContent}`;
119
- result = await chat.sendMessage(AI.userMsg);
120
- } else {
121
- result = await chat.sendMessage(AI.userMsg);
122
- }
123
-
124
- const response = await result.response.text();
125
-
126
-
127
- if (message.db) {
128
- const combinedHistoryUpdate = {
129
- $push: {
130
- "history": {
131
- $each: [
132
- {
133
- role: "user",
134
- parts: [{ text: `${AI.userMsg}` }]
135
- },
136
- {
137
- role: "model",
138
- parts: [{ text: `${response}` }]
139
- }
140
- ]
141
- }
142
- },
143
- };
144
-
145
- historyData = await db.update(
146
- `${message.userId}_chatHistory`,
147
- { userId: message.userId },
148
- combinedHistoryUpdate,
149
- true
150
- );
151
- }
152
-
153
- return response;
154
- }
155
-
156
- async function urlToBase64(imageURL: string) {
157
- try {
158
- const convertedBuffer = await converter(imageURL, 'png');
159
- const base64String = convertedBuffer.toString('base64');
160
- return base64String;
161
- } catch (error: any) {
162
- throw new Error(`Failed to fetch and convert the image: ${error.message}`);
163
- }
164
- }
165
-
166
- try {
167
- if (AI.API_KEY && !(await validateKey(AI.API_KEY))) {
168
- return 'Invalid API key provided.';
169
- }
170
-
171
- function getRandomApiKey() {
172
- const { apiKeys } = config;
173
- const randomIndex = Math.floor(Math.random() * apiKeys.length);
174
- return apiKeys[randomIndex];
175
- }
176
-
177
- const randomApiKey = getRandomApiKey();
178
-
179
- const genAI = new GoogleGenerativeAI(AI.API_KEY || randomApiKey);
180
- return await processRequest(genAI);
181
-
182
- } catch (e: any) {
183
- if (e.message) {
184
- if (e.status === 429 || e.status === 403) {
185
- return 'AI is on a cooldown for the rest of the day. Either provide a new API key or wait for tomorrow. Check ai.google.dev for free API keys.';
186
- } else if (e.status === 400) {
187
- return 'The hoster/bot owner/the used host isn\'t supported by Gemini.';
188
- } else if (e.message === '[GoogleGenerativeAI Error]: Candidate was blocked due to SAFETY') {
189
- console.error(e);
190
- return 'Due to safety enabled by Gemini, you have been blocked.';
191
- } else {
192
- console.error(e);
193
- return 'Try again later please... Either API is on a cooldown or an internal server error has occurred. If issue persists, please contact the bot developer or owner of the npm package.';
194
- }
195
- } else {
196
- console.error(e);
197
- return 'An unknown error has occurred.';
198
- }
199
- }
200
- }
@@ -1,203 +0,0 @@
1
- import { GoogleGenerativeAI, HarmCategory, HarmBlockThreshold } from "@google/generative-ai";
2
- import { converter } from "../../../canvas/utils/general functions";
3
- import { GoogleAIFileManager } from "@google/generative-ai/server";
4
-
5
- import { connect } from "verse.db";
6
- import config from './config';
7
- import axios from "axios";
8
- import path from 'path';
9
- import fs from 'fs';
10
- import { readFile } from "../../utils";
11
-
12
- export async function geminiPro(message: { userId: string, serverName: string, serverId: string, channelName: string, attachment: any, db: boolean }, AI: { AiPersonality: string | null, userMsg: string, API_KEY: string | null }): Promise<any> {
13
-
14
- async function validateKey(apiKey: string) {
15
-
16
- try {
17
- const validateResponse = await axios.get(`https://generativelanguage.googleapis.com/v1beta/models?key=${apiKey}`);
18
- return validateResponse.status === 200;
19
- } catch (error) {
20
- console.error(`Error validating API key: ${apiKey}`, error);
21
- return false;
22
- }
23
- }
24
-
25
- async function processRequest(genAI: any): Promise<any> {
26
- let personalityString = '';
27
-
28
- if (AI.AiPersonality) {
29
- const personalityFilePath = path.join(process.cwd(), AI.AiPersonality);
30
- const personalityContent = fs.readFileSync(personalityFilePath, 'utf-8');
31
- personalityString = personalityContent.split('\n').join(' ');
32
- }
33
-
34
- const generationConfig = {
35
- maxOutputTokens: 1048576,
36
- };
37
-
38
- const safetySettings = [
39
- {
40
- category: HarmCategory.HARM_CATEGORY_HARASSMENT,
41
- threshold: HarmBlockThreshold.BLOCK_NONE,
42
- },
43
- {
44
- category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
45
- threshold: HarmBlockThreshold.BLOCK_NONE,
46
- },
47
- {
48
- category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
49
- threshold: HarmBlockThreshold.BLOCK_NONE,
50
- },
51
- {
52
- category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
53
- threshold: HarmBlockThreshold.BLOCK_NONE,
54
- },
55
- ];
56
-
57
-
58
- const systemInstruction = `${personalityString}\n And working on discord in serverName: ${message.serverName} at channelName: ${message.channelName} and responding to the userName: <@${message.userId}>`;
59
- const model = genAI.getGenerativeModel({ model: "gemini-1.5-pro-latest", systemInstruction, generationConfig, safetySettings });
60
-
61
- const defaultHistory = [
62
- {
63
- role: "user",
64
- parts: [{ text: `Hey who are you?` }],
65
- },
66
- {
67
- role: "model",
68
- parts: [{ text: `I am an AI assistant built/developed/created by Apexify.js` }],
69
- },
70
- {
71
- role: "user",
72
- parts: [{ text: `You have chat Memory?` }],
73
- },
74
- {
75
- role: "model",
76
- parts: [{ text: `Yes, I save chat history for each user if it is enabled in my configuration otherwise no data being saved.` }],
77
- },
78
- {
79
- role: "user",
80
- parts: [{ text: `How is your data/memory/chat history managed?` }],
81
- },
82
- {
83
- role: "model",
84
- parts: [{ text: `It is managed by verse.db. A database used to manage JSON/SQL/YAML/SQON database with ease and supports schema/schemaless data.` }],
85
- }
86
- ];
87
-
88
- let historyData: any[] | undefined = undefined;
89
-
90
- let db: any;
91
- if (message.db) {
92
- db = new connect({ adapter: 'json', dataPath: `${message.serverId}_ChatHistory` });
93
- const data = await db.find(`${message.userId}_chatHistory`, { userId: message.userId });
94
- historyData = data.results?.history.slice(-100) || undefined;
95
- }
96
-
97
- const chat = model.startChat({
98
- history: historyData || defaultHistory,
99
- generationConfig
100
- });
101
-
102
- const imgURL = message.attachment?.url || null;
103
- let result: any;
104
-
105
- if (imgURL && message.attachment?.contentType?.startsWith("image/")) {
106
- const url = await urlToBase64(imgURL);
107
-
108
- result = await model.generateContent([AI.userMsg, {
109
- inlineData: {
110
- data: url,
111
- mimeType: message.attachment?.contentType
112
- }
113
- }]);
114
-
115
- } else if (message.attachment?.name.endsWith('.pdf')) {
116
- const pdfContent = await readFile(message.attachment?.url, 'pdf');
117
- AI.userMsg += `\n\n- This is the PDF file content:\n\n ${pdfContent}`;
118
- result = await chat.sendMessage(AI.userMsg);
119
- } else if (message.attachment?.name.endsWith('.txt')) {
120
- const txtContent = await readFile(message.attachment?.url, 'txt');
121
- AI.userMsg += `\n\n- This is the .txt file content:\n\n ${txtContent}`;
122
- result = await chat.sendMessage(AI.userMsg);
123
- } else {
124
- result = await chat.sendMessage(AI.userMsg);
125
- }
126
-
127
- const response = await result.response.text();
128
-
129
- if (message.db) {
130
- const combinedHistoryUpdate = {
131
- $push: {
132
- "history": {
133
- $each: [
134
- {
135
- role: "user",
136
- parts: [{ text: `${AI.userMsg}` }]
137
- },
138
- {
139
- role: "model",
140
- parts: [{ text: `${response}` }]
141
- }
142
- ]
143
- }
144
- },
145
- };
146
-
147
- historyData = await db.update(
148
- `${message.userId}_chatHistory`,
149
- { userId: message.userId },
150
- combinedHistoryUpdate,
151
- true
152
- );
153
- }
154
-
155
- return response;
156
- }
157
-
158
- async function urlToBase64(imageURL: string) {
159
- try {
160
- const convertedBuffer = await converter(imageURL, 'png');
161
- const base64String = convertedBuffer.toString('base64');
162
-
163
- return base64String;
164
- } catch (error: any) {
165
- throw new Error(`Failed to fetch and convert the image: ${error.message}`);
166
- }
167
- }
168
-
169
- try {
170
- if (AI.API_KEY && !(await validateKey(AI.API_KEY))) {
171
- return 'Invalid API key provided.';
172
- }
173
-
174
- function getRandomApiKey() {
175
- const { apiKeys } = config;
176
- const randomIndex = Math.floor(Math.random() * apiKeys.length);
177
- return apiKeys[randomIndex];
178
- }
179
-
180
- const randomApiKey = getRandomApiKey();
181
-
182
- const genAI = new GoogleGenerativeAI(AI.API_KEY || randomApiKey);
183
- return await processRequest(genAI);
184
-
185
- } catch (e: any) {
186
- if (e.message) {
187
- if (e.status === 429 || e.status === 403) {
188
- return 'AI is on a cooldown for the rest of the day. Either provide a new API key or wait for tomorrow. Check ai.google.dev for free API keys.';
189
- } else if (e.status === 400) {
190
- return 'The hoster/bot owner/the used host isn\'t supported by Gemini.';
191
- } else if (e.message === '[GoogleGenerativeAI Error]: Candidate was blocked due to SAFETY') {
192
- console.error(e);
193
- return 'Due to safety enabled by Gemini, you have been blocked.';
194
- } else {
195
- console.error(e);
196
- return 'Try again later please... Either API is on a cooldown or an internal server error has occurred. If issue persists, please contact the bot developer or owner of the npm package.';
197
- }
198
- } else {
199
- console.error(e);
200
- return 'An unknown error has occurred.';
201
- }
202
- }
203
- }
@@ -1,11 +0,0 @@
1
- const config = {
2
- apiKeys: [
3
- "AIzaSyAdlBVg12yjqqGfBqxT5DLGMhP2jysG7Hk",
4
- "AIzaSyCiko-Viy8FduRAtT-X1T598n-24t0ATK0",
5
- "AIzaSyC4K7fWab65-Ol4g13FIdJcKAlBIJLPOgA",
6
- "AIzaSyC2Ga-8e-lRr6D_ehiGlxIUK8Fx7_f9tvk",
7
- "AIzaSyA2dOYNHZ2O08fBu4rr4YtXO8OskFpRxYo"
8
- ]
9
- };
10
-
11
- export default config;
@@ -1,169 +0,0 @@
1
- import { GoogleGenerativeAI, HarmCategory, HarmBlockThreshold } from "@google/generative-ai";
2
- import { connect } from "verse.db";
3
- import config from './config';
4
- import axios from "axios";
5
-
6
- interface gemini{
7
- Api_key?: string;
8
- modal: string;
9
- memory?: boolean;
10
- user?: string;
11
- instruction?: string;
12
- prompt: string;
13
- limit?: number;
14
- }
15
- export async function geminiFast({ Api_key, modal, memory, user, instruction, prompt, limit }: gemini, { url = '', type = '' }: { url?: string, type?: string } = {} ): Promise<any> {
16
-
17
- async function validateKey(apiKey: string) {
18
- try {
19
- const validateResponse = await axios.get(`https://generativelanguage.googleapis.com/v1beta/models?key=${apiKey}`);
20
- return validateResponse.status === 200;
21
- } catch (error) {
22
- console.error(`Error validating API key: ${apiKey}`, error);
23
- return false;
24
- }
25
- }
26
-
27
- async function processRequest(genAI: any): Promise<any> {
28
-
29
- const generationConfig = {
30
- maxOutputTokens: 1048576,
31
- };
32
-
33
- const safetySettings = [
34
- {
35
- category: HarmCategory.HARM_CATEGORY_HARASSMENT,
36
- threshold: HarmBlockThreshold.BLOCK_NONE,
37
- },
38
- {
39
- category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
40
- threshold: HarmBlockThreshold.BLOCK_NONE,
41
- },
42
- {
43
- category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
44
- threshold: HarmBlockThreshold.BLOCK_NONE,
45
- },
46
- {
47
- category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
48
- threshold: HarmBlockThreshold.BLOCK_NONE,
49
- },
50
- ];
51
-
52
-
53
- const systemInstruction = `${instruction}`;
54
- if (modal === 'gemini-flash') modal = 'gemini-1.5-flash-latest'
55
- if (modal === 'gemini-pro') modal = 'gemini-1.5-pro-latest'
56
-
57
- const model = genAI.getGenerativeModel({ model: modal, systemInstruction, generationConfig, safetySettings });
58
-
59
- const defaultHistory = [
60
- {
61
- role: "user",
62
- parts: [{ text: `Hey who are you?` }],
63
- },
64
- {
65
- role: "model",
66
- parts: [{ text: `I am an AI assistant built/developed/created by Apexify.js` }],
67
- },
68
- {
69
- role: "user",
70
- parts: [{ text: `You have chat Memory?` }],
71
- },
72
- {
73
- role: "model",
74
- parts: [{ text: `Yes, I save chat history for each user if it is enabled in my configuration otherwise no data being saved.` }],
75
- },
76
- {
77
- role: "user",
78
- parts: [{ text: `How is your data/memory/chat history managed?` }],
79
- },
80
- {
81
- role: "model",
82
- parts: [{ text: `It is managed by verse.db. A database used to manage JSON/SQL/YAML/SQON/Session Data/Cache Data database with ease and supports schema/schemaless data.` }],
83
- }
84
- ];
85
-
86
- let historyData: any[] | undefined = undefined;
87
-
88
- let db: any;
89
- if (memory && user) {
90
- db = new connect({ adapter: 'json', dataPath: `Gemini_ChatHistory` });
91
- const data = await db.find(`${user}`, { userId: user });
92
- historyData = data.results?.history.slice(-(limit || 100)) || undefined;
93
- }
94
-
95
- const chat = model.startChat({
96
- history: historyData || defaultHistory,
97
- generationConfig
98
- });
99
-
100
- const result = await chat.sendMessage(prompt);
101
-
102
-
103
- const response = await result.response.text();
104
-
105
- if (memory && user) {
106
- const combinedHistoryUpdate = {
107
- $push: {
108
- "history": {
109
- $each: [
110
- {
111
- role: "user",
112
- parts: [{ text: `${prompt}` }]
113
- },
114
- {
115
- role: "model",
116
- parts: [{ text: `${response}` }]
117
- }
118
- ]
119
- }
120
- },
121
- };
122
-
123
- historyData = await db.update(
124
- `${user}`,
125
- { userId: user },
126
- combinedHistoryUpdate,
127
- true
128
- );
129
- }
130
-
131
- return response;
132
- }
133
-
134
-
135
- try {
136
- if (Api_key && !(await validateKey(Api_key))) {
137
- return 'Invalid API key provided.';
138
- }
139
-
140
- function getRandomApiKey() {
141
- const { apiKeys } = config;
142
- const randomIndex = Math.floor(Math.random() * apiKeys.length);
143
- return apiKeys[randomIndex];
144
- }
145
-
146
- const randomApiKey = getRandomApiKey();
147
-
148
- const genAI = new GoogleGenerativeAI(Api_key || randomApiKey);
149
- return await processRequest(genAI);
150
-
151
- } catch (e: any) {
152
- if (e.message) {
153
- if (e.status === 429 || e.status === 403) {
154
- return 'AI is on a cooldown for the rest of the day. Either provide a new API key or wait for tomorrow. Check ai.google.dev for free API keys.';
155
- } else if (e.status === 400) {
156
- return 'The hoster/bot owner/the used host isn\'t supported by Gemini.';
157
- } else if (e.message === '[GoogleGenerativeAI Error]: Candidate was blocked due to SAFETY') {
158
- console.error(e);
159
- return 'Due to safety enabled by Gemini, you have been blocked.';
160
- } else {
161
- console.error(e);
162
- return 'Try again later please... Either API is on a cooldown or an internal server error has occurred. If issue persists, please contact the bot developer or owner of the npm package.';
163
- }
164
- } else {
165
- console.error(e);
166
- return 'An unknown error has occurred.';
167
- }
168
- }
169
- }
@@ -1,120 +0,0 @@
1
- import { loadImage } from "@napi-rs/canvas";
2
- import { CanvasConfig } from './types';
3
- import path from 'path';
4
-
5
- /**
6
- * Draws a solid background color on the canvas.
7
- * Applies zoom scaling and positioning adjustments.
8
- * @param ctx The canvas rendering context.
9
- * @param canvas The canvas configuration object.
10
- */
11
- export async function drawBackgroundColor(ctx: any, canvas: CanvasConfig): Promise<void> {
12
- const zoomScale = canvas.zoom?.scale || 1;
13
- const zoomX = canvas.zoom?.x || 0;
14
- const zoomY = canvas.zoom?.y || 0;
15
-
16
- const canvasWidth = canvas.width || 500;
17
- const canvasHeight = canvas.height || 500;
18
-
19
- const newWidth = canvasWidth * zoomScale;
20
- const newHeight = canvasHeight * zoomScale;
21
-
22
- const drawX = (canvasWidth - newWidth) / 2 - zoomX;
23
- const drawY = (canvasHeight - newHeight) / 2 - zoomY;
24
-
25
- if (canvas.colorBg !== 'transparent') {
26
- ctx.fillStyle = canvas.colorBg;
27
- ctx.fillRect(drawX, drawY, newWidth, newHeight);
28
- }
29
- }
30
-
31
- /**
32
- * Draws a gradient background on the canvas.
33
- * Applies zoom scaling and positioning adjustments.
34
- * @param ctx The canvas rendering context.
35
- * @param canvas The canvas configuration object.
36
- */
37
- export async function drawBackgroundGradient(ctx: any, canvas: CanvasConfig): Promise<void> {
38
- if (canvas.gradientBg) {
39
- const { type, startX = 0, startY = 0, endX = canvas.width || 500, endY = canvas.height || 500, startRadius = 0, endRadius = 0, colors } = canvas.gradientBg;
40
-
41
- if (!colors || colors.length === 0) {
42
- throw new Error('You need to provide colors for the gradient.');
43
- }
44
-
45
- let gradient;
46
- const zoomScale = canvas.zoom?.scale || 1;
47
- const zoomX = canvas.zoom?.x || 0;
48
- const zoomY = canvas.zoom?.y || 0;
49
-
50
- const newStartX = startX * zoomScale - zoomX;
51
- const newStartY = startY * zoomScale - zoomY;
52
- const newEndX = endX * zoomScale - zoomX;
53
- const newEndY = endY * zoomScale - zoomY;
54
-
55
- if (type === 'linear' || type === undefined) {
56
- gradient = ctx.createLinearGradient(newStartX, newStartY, newEndX, newEndY);
57
- } else if (type === 'radial') {
58
- const newStartRadius = startRadius * zoomScale;
59
- const newEndRadius = endRadius * zoomScale;
60
- gradient = ctx.createRadialGradient(newStartX, newStartY, newStartRadius, newEndX, newEndY, newEndRadius);
61
- } else {
62
- throw new Error('Unsupported gradient type.');
63
- }
64
-
65
- for (const { stop, color } of colors) {
66
- gradient.addColorStop(stop, color);
67
- }
68
-
69
- const newWidth = (canvas.width || 500) * zoomScale;
70
- const newHeight = (canvas.height || 500) * zoomScale;
71
- const drawX = ((canvas.width || 500) - newWidth) / 2 - zoomX;
72
- const drawY = ((canvas.height || 500) - newHeight) / 2 - zoomY;
73
-
74
- ctx.fillStyle = gradient;
75
- ctx.fillRect(drawX, drawY, newWidth, newHeight);
76
- }
77
- }
78
-
79
- /**
80
- * Draws a custom background image on the canvas.
81
- * Zoom logic is applied to scale and position the image.
82
- * @param ctx The canvas rendering context.
83
- * @param canvas The canvas configuration object.
84
- */
85
- export async function customBackground(ctx: any, canvas: CanvasConfig): Promise<void> {
86
- if (canvas.customBg) {
87
- try {
88
- let imageBuffer: string;
89
-
90
- if (canvas.customBg.startsWith('http')) {
91
- imageBuffer = canvas.customBg;
92
- } else {
93
- imageBuffer = path.join(process.cwd(), canvas.customBg);
94
- }
95
-
96
- const image = await loadImage(imageBuffer);
97
- const zoomScale = canvas.zoom?.scale || 1;
98
-
99
- if (zoomScale < 0) throw new Error("Invalid scale. Scale can't be a negative integer.");
100
-
101
- const zoomX = canvas.zoom?.x || 0;
102
- const zoomY = canvas.zoom?.y || 0;
103
- const moveX = canvas.x || 0;
104
- const moveY = canvas.y || 0;
105
-
106
- const canvasWidth = canvas.width || image.width;
107
- const canvasHeight = canvas.height || image.height;
108
-
109
- const newWidth = image.width * zoomScale;
110
- const newHeight = image.height * zoomScale;
111
- const drawX = moveX + (canvasWidth - newWidth) / 2 - zoomX;
112
- const drawY = moveY + (canvasHeight - newHeight) / 2 - zoomY;
113
-
114
- ctx.drawImage(image, drawX, drawY, newWidth, newHeight);
115
-
116
- } catch (error: any) {
117
- console.error('Error loading custom background image:', error.message);
118
- }
119
- }
120
- }