apexify.js 4.5.54 → 4.5.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/ai/ApexAI.d.ts +1 -164
- package/dist/cjs/ai/ApexAI.d.ts.map +1 -1
- package/dist/cjs/ai/ApexAI.js +190 -373
- package/dist/cjs/ai/ApexAI.js.map +1 -1
- package/dist/cjs/ai/ApexModules.d.ts +1 -1
- package/dist/cjs/ai/ApexModules.d.ts.map +1 -1
- package/dist/cjs/ai/ApexModules.js +6 -18
- package/dist/cjs/ai/ApexModules.js.map +1 -1
- package/dist/cjs/ai/functions/draw.d.ts.map +1 -1
- package/dist/cjs/ai/functions/draw.js +6 -6
- package/dist/cjs/ai/functions/draw.js.map +1 -1
- package/dist/cjs/ai/modals-chat/electronHub/imageModels.d.ts +1 -1
- package/dist/cjs/ai/modals-chat/electronHub/imageModels.d.ts.map +1 -1
- package/dist/cjs/ai/modals-chat/electronHub/imageModels.js +1 -4
- package/dist/cjs/ai/modals-chat/electronHub/imageModels.js.map +1 -1
- package/dist/cjs/ai/utils.d.ts +1 -4
- package/dist/cjs/ai/utils.d.ts.map +1 -1
- package/dist/cjs/ai/utils.js +1 -7
- package/dist/cjs/ai/utils.js.map +1 -1
- package/dist/cjs/canvas/ApexPainter.d.ts +17 -14
- package/dist/cjs/canvas/ApexPainter.d.ts.map +1 -1
- package/dist/cjs/canvas/ApexPainter.js +29 -11
- package/dist/cjs/canvas/ApexPainter.js.map +1 -1
- package/dist/cjs/canvas/utils/Background/bg.d.ts +24 -0
- package/dist/cjs/canvas/utils/Background/bg.d.ts.map +1 -0
- package/dist/{esm/canvas/utils → cjs/canvas/utils/Background}/bg.js +27 -52
- package/dist/cjs/canvas/utils/Background/bg.js.map +1 -0
- package/dist/cjs/canvas/utils/Background/circular.d.ts +3 -0
- package/dist/cjs/canvas/utils/Background/circular.d.ts.map +1 -0
- package/dist/{esm/canvas/utils → cjs/canvas/utils/Background}/circular.js +0 -8
- package/dist/cjs/canvas/utils/{circular.js.map → Background/circular.js.map} +1 -1
- package/dist/cjs/canvas/utils/Background/radius.d.ts +18 -0
- package/dist/cjs/canvas/utils/Background/radius.d.ts.map +1 -0
- package/dist/cjs/canvas/utils/Background/radius.js +115 -0
- package/dist/cjs/canvas/utils/Background/radius.js.map +1 -0
- package/dist/cjs/canvas/utils/{charts.d.ts → Charts/charts.d.ts} +1 -1
- package/dist/cjs/canvas/utils/Charts/charts.d.ts.map +1 -0
- package/dist/cjs/canvas/utils/Charts/charts.js.map +1 -0
- package/dist/cjs/canvas/utils/Custom/customLines.d.ts +3 -0
- package/dist/cjs/canvas/utils/Custom/customLines.d.ts.map +1 -0
- package/dist/cjs/canvas/utils/Custom/customLines.js.map +1 -0
- package/dist/cjs/canvas/utils/General/conversion.d.ts.map +1 -0
- package/dist/cjs/canvas/utils/General/conversion.js.map +1 -0
- package/dist/cjs/canvas/utils/{general functions.d.ts → General/general functions.d.ts } +18 -4
- package/dist/cjs/canvas/utils/General/general functions.d.ts.map +1 -0
- package/dist/{esm/canvas/utils → cjs/canvas/utils/General}/general functions.js +89 -58
- package/dist/cjs/canvas/utils/General/general functions.js.map +1 -0
- package/dist/cjs/canvas/utils/Image/imageProperties.d.ts +81 -0
- package/dist/cjs/canvas/utils/Image/imageProperties.d.ts.map +1 -0
- package/dist/{esm/canvas/utils → cjs/canvas/utils/Image}/imageProperties.js +224 -45
- package/dist/cjs/canvas/utils/Image/imageProperties.js.map +1 -0
- package/dist/{esm/canvas/utils → cjs/canvas/utils/Texts}/textProperties.d.ts +1 -1
- package/dist/cjs/canvas/utils/Texts/textProperties.d.ts.map +1 -0
- package/dist/cjs/canvas/utils/Texts/textProperties.js.map +1 -0
- package/dist/cjs/canvas/utils/types.d.ts +41 -1
- package/dist/cjs/canvas/utils/types.d.ts.map +1 -1
- package/dist/cjs/canvas/utils/types.js.map +1 -1
- package/dist/cjs/canvas/utils/utils.d.ts +11 -11
- package/dist/cjs/canvas/utils/utils.d.ts.map +1 -1
- package/dist/cjs/canvas/utils/utils.js +11 -10
- package/dist/cjs/canvas/utils/utils.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/ai/ApexAI.d.ts +1 -164
- package/dist/esm/ai/ApexAI.d.ts.map +1 -1
- package/dist/esm/ai/ApexAI.js +190 -373
- package/dist/esm/ai/ApexAI.js.map +1 -1
- package/dist/esm/ai/ApexModules.d.ts +1 -1
- package/dist/esm/ai/ApexModules.d.ts.map +1 -1
- package/dist/esm/ai/ApexModules.js +6 -18
- package/dist/esm/ai/ApexModules.js.map +1 -1
- package/dist/esm/ai/functions/draw.d.ts.map +1 -1
- package/dist/esm/ai/functions/draw.js +6 -6
- package/dist/esm/ai/functions/draw.js.map +1 -1
- package/dist/esm/ai/modals-chat/electronHub/imageModels.d.ts +1 -1
- package/dist/esm/ai/modals-chat/electronHub/imageModels.d.ts.map +1 -1
- package/dist/esm/ai/modals-chat/electronHub/imageModels.js +1 -4
- package/dist/esm/ai/modals-chat/electronHub/imageModels.js.map +1 -1
- package/dist/esm/ai/utils.d.ts +1 -4
- package/dist/esm/ai/utils.d.ts.map +1 -1
- package/dist/esm/ai/utils.js +1 -7
- package/dist/esm/ai/utils.js.map +1 -1
- package/dist/esm/canvas/ApexPainter.d.ts +17 -14
- package/dist/esm/canvas/ApexPainter.d.ts.map +1 -1
- package/dist/esm/canvas/ApexPainter.js +29 -11
- package/dist/esm/canvas/ApexPainter.js.map +1 -1
- package/dist/esm/canvas/utils/Background/bg.d.ts +24 -0
- package/dist/esm/canvas/utils/Background/bg.d.ts.map +1 -0
- package/dist/{cjs/canvas/utils → esm/canvas/utils/Background}/bg.js +27 -52
- package/dist/esm/canvas/utils/Background/bg.js.map +1 -0
- package/dist/esm/canvas/utils/Background/circular.d.ts +3 -0
- package/dist/esm/canvas/utils/Background/circular.d.ts.map +1 -0
- package/dist/{cjs/canvas/utils → esm/canvas/utils/Background}/circular.js +0 -8
- package/dist/esm/canvas/utils/{circular.js.map → Background/circular.js.map} +1 -1
- package/dist/esm/canvas/utils/Background/radius.d.ts +18 -0
- package/dist/esm/canvas/utils/Background/radius.d.ts.map +1 -0
- package/dist/esm/canvas/utils/Background/radius.js +115 -0
- package/dist/esm/canvas/utils/Background/radius.js.map +1 -0
- package/dist/esm/canvas/utils/{charts.d.ts → Charts/charts.d.ts} +1 -1
- package/dist/esm/canvas/utils/Charts/charts.d.ts.map +1 -0
- package/dist/esm/canvas/utils/Charts/charts.js.map +1 -0
- package/dist/esm/canvas/utils/Custom/customLines.d.ts +3 -0
- package/dist/esm/canvas/utils/Custom/customLines.d.ts.map +1 -0
- package/dist/esm/canvas/utils/Custom/customLines.js.map +1 -0
- package/dist/esm/canvas/utils/General/conversion.d.ts.map +1 -0
- package/dist/esm/canvas/utils/General/conversion.js.map +1 -0
- package/dist/esm/canvas/utils/{general functions.d.ts → General/general functions.d.ts } +18 -4
- package/dist/esm/canvas/utils/General/general functions.d.ts.map +1 -0
- package/dist/{cjs/canvas/utils → esm/canvas/utils/General}/general functions.js +89 -58
- package/dist/esm/canvas/utils/General/general functions.js.map +1 -0
- package/dist/esm/canvas/utils/Image/imageProperties.d.ts +81 -0
- package/dist/esm/canvas/utils/Image/imageProperties.d.ts.map +1 -0
- package/dist/{cjs/canvas/utils → esm/canvas/utils/Image}/imageProperties.js +224 -45
- package/dist/esm/canvas/utils/Image/imageProperties.js.map +1 -0
- package/dist/{cjs/canvas/utils → esm/canvas/utils/Texts}/textProperties.d.ts +1 -1
- package/dist/esm/canvas/utils/Texts/textProperties.d.ts.map +1 -0
- package/dist/esm/canvas/utils/Texts/textProperties.js.map +1 -0
- package/dist/esm/canvas/utils/types.d.ts +41 -1
- package/dist/esm/canvas/utils/types.d.ts.map +1 -1
- package/dist/esm/canvas/utils/types.js.map +1 -1
- package/dist/esm/canvas/utils/utils.d.ts +11 -11
- package/dist/esm/canvas/utils/utils.d.ts.map +1 -1
- package/dist/esm/canvas/utils/utils.js +11 -10
- package/dist/esm/canvas/utils/utils.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/ai/ApexAI.ts +195 -697
- package/lib/ai/ApexModules.ts +7 -17
- package/lib/ai/functions/draw.ts +6 -8
- package/lib/ai/modals-chat/electronHub/imageModels.ts +2 -5
- package/lib/ai/utils.ts +0 -6
- package/lib/canvas/ApexPainter.ts +73 -38
- package/lib/canvas/utils/Background/bg.ts +97 -0
- package/lib/canvas/utils/Background/circular.ts +17 -0
- package/lib/canvas/utils/Background/radius.ts +113 -0
- package/lib/canvas/utils/{charts.ts → Charts/charts.ts} +1 -1
- package/lib/canvas/utils/{customLines.ts → Custom/customLines.ts} +1 -1
- package/lib/canvas/utils/{conversion.ts → General/conversion.ts} +1 -1
- package/lib/canvas/utils/{general functions.ts → General/general functions.ts } +143 -121
- package/lib/canvas/utils/Image/imageProperties.ts +631 -0
- package/lib/canvas/utils/{textProperties.ts → Texts/textProperties.ts} +1 -1
- package/lib/canvas/utils/types.ts +45 -2
- package/lib/canvas/utils/utils.ts +14 -11
- package/package.json +1 -4
- package/dist/cjs/ai/functions/generateVoiceResponse.d.ts +0 -10
- package/dist/cjs/ai/functions/generateVoiceResponse.d.ts.map +0 -1
- package/dist/cjs/ai/functions/generateVoiceResponse.js +0 -161
- package/dist/cjs/ai/functions/generateVoiceResponse.js.map +0 -1
- package/dist/cjs/ai/modals-chat/gemini/Gemini-flash.d.ts +0 -13
- package/dist/cjs/ai/modals-chat/gemini/Gemini-flash.d.ts.map +0 -1
- package/dist/cjs/ai/modals-chat/gemini/Gemini-flash.js +0 -185
- package/dist/cjs/ai/modals-chat/gemini/Gemini-flash.js.map +0 -1
- package/dist/cjs/ai/modals-chat/gemini/Gemini-pro.d.ts +0 -13
- package/dist/cjs/ai/modals-chat/gemini/Gemini-pro.d.ts.map +0 -1
- package/dist/cjs/ai/modals-chat/gemini/Gemini-pro.js +0 -185
- package/dist/cjs/ai/modals-chat/gemini/Gemini-pro.js.map +0 -1
- package/dist/cjs/ai/modals-chat/gemini/config.d.ts +0 -5
- package/dist/cjs/ai/modals-chat/gemini/config.d.ts.map +0 -1
- package/dist/cjs/ai/modals-chat/gemini/config.js +0 -13
- package/dist/cjs/ai/modals-chat/gemini/config.js.map +0 -1
- package/dist/cjs/ai/modals-chat/gemini/geminiFast.d.ts +0 -15
- package/dist/cjs/ai/modals-chat/gemini/geminiFast.d.ts.map +0 -1
- package/dist/cjs/ai/modals-chat/gemini/geminiFast.js +0 -146
- package/dist/cjs/ai/modals-chat/gemini/geminiFast.js.map +0 -1
- package/dist/cjs/canvas/utils/bg.d.ts +0 -23
- package/dist/cjs/canvas/utils/bg.d.ts.map +0 -1
- package/dist/cjs/canvas/utils/bg.js.map +0 -1
- package/dist/cjs/canvas/utils/charts.d.ts.map +0 -1
- package/dist/cjs/canvas/utils/charts.js.map +0 -1
- package/dist/cjs/canvas/utils/circular.d.ts +0 -10
- package/dist/cjs/canvas/utils/circular.d.ts.map +0 -1
- package/dist/cjs/canvas/utils/conversion.d.ts.map +0 -1
- package/dist/cjs/canvas/utils/conversion.js.map +0 -1
- package/dist/cjs/canvas/utils/customLines.d.ts +0 -3
- package/dist/cjs/canvas/utils/customLines.d.ts.map +0 -1
- package/dist/cjs/canvas/utils/customLines.js.map +0 -1
- package/dist/cjs/canvas/utils/general functions.d.ts.map +0 -1
- package/dist/cjs/canvas/utils/general functions.js.map +0 -1
- package/dist/cjs/canvas/utils/imageProperties.d.ts +0 -62
- package/dist/cjs/canvas/utils/imageProperties.d.ts.map +0 -1
- package/dist/cjs/canvas/utils/imageProperties.js.map +0 -1
- package/dist/cjs/canvas/utils/radius.d.ts +0 -10
- package/dist/cjs/canvas/utils/radius.d.ts.map +0 -1
- package/dist/cjs/canvas/utils/radius.js +0 -30
- package/dist/cjs/canvas/utils/radius.js.map +0 -1
- package/dist/cjs/canvas/utils/textProperties.d.ts.map +0 -1
- package/dist/cjs/canvas/utils/textProperties.js.map +0 -1
- package/dist/esm/ai/functions/generateVoiceResponse.d.ts +0 -10
- package/dist/esm/ai/functions/generateVoiceResponse.d.ts.map +0 -1
- package/dist/esm/ai/functions/generateVoiceResponse.js +0 -161
- package/dist/esm/ai/functions/generateVoiceResponse.js.map +0 -1
- package/dist/esm/ai/modals-chat/gemini/Gemini-flash.d.ts +0 -13
- package/dist/esm/ai/modals-chat/gemini/Gemini-flash.d.ts.map +0 -1
- package/dist/esm/ai/modals-chat/gemini/Gemini-flash.js +0 -185
- package/dist/esm/ai/modals-chat/gemini/Gemini-flash.js.map +0 -1
- package/dist/esm/ai/modals-chat/gemini/Gemini-pro.d.ts +0 -13
- package/dist/esm/ai/modals-chat/gemini/Gemini-pro.d.ts.map +0 -1
- package/dist/esm/ai/modals-chat/gemini/Gemini-pro.js +0 -185
- package/dist/esm/ai/modals-chat/gemini/Gemini-pro.js.map +0 -1
- package/dist/esm/ai/modals-chat/gemini/config.d.ts +0 -5
- package/dist/esm/ai/modals-chat/gemini/config.d.ts.map +0 -1
- package/dist/esm/ai/modals-chat/gemini/config.js +0 -13
- package/dist/esm/ai/modals-chat/gemini/config.js.map +0 -1
- package/dist/esm/ai/modals-chat/gemini/geminiFast.d.ts +0 -15
- package/dist/esm/ai/modals-chat/gemini/geminiFast.d.ts.map +0 -1
- package/dist/esm/ai/modals-chat/gemini/geminiFast.js +0 -146
- package/dist/esm/ai/modals-chat/gemini/geminiFast.js.map +0 -1
- package/dist/esm/canvas/utils/bg.d.ts +0 -23
- package/dist/esm/canvas/utils/bg.d.ts.map +0 -1
- package/dist/esm/canvas/utils/bg.js.map +0 -1
- package/dist/esm/canvas/utils/charts.d.ts.map +0 -1
- package/dist/esm/canvas/utils/charts.js.map +0 -1
- package/dist/esm/canvas/utils/circular.d.ts +0 -10
- package/dist/esm/canvas/utils/circular.d.ts.map +0 -1
- package/dist/esm/canvas/utils/conversion.d.ts.map +0 -1
- package/dist/esm/canvas/utils/conversion.js.map +0 -1
- package/dist/esm/canvas/utils/customLines.d.ts +0 -3
- package/dist/esm/canvas/utils/customLines.d.ts.map +0 -1
- package/dist/esm/canvas/utils/customLines.js.map +0 -1
- package/dist/esm/canvas/utils/general functions.d.ts.map +0 -1
- package/dist/esm/canvas/utils/general functions.js.map +0 -1
- package/dist/esm/canvas/utils/imageProperties.d.ts +0 -62
- package/dist/esm/canvas/utils/imageProperties.d.ts.map +0 -1
- package/dist/esm/canvas/utils/imageProperties.js.map +0 -1
- package/dist/esm/canvas/utils/radius.d.ts +0 -10
- package/dist/esm/canvas/utils/radius.d.ts.map +0 -1
- package/dist/esm/canvas/utils/radius.js +0 -30
- package/dist/esm/canvas/utils/radius.js.map +0 -1
- package/dist/esm/canvas/utils/textProperties.d.ts.map +0 -1
- package/dist/esm/canvas/utils/textProperties.js.map +0 -1
- package/lib/ai/functions/generateVoiceResponse.ts +0 -186
- package/lib/ai/modals-chat/gemini/Gemini-flash.ts +0 -200
- package/lib/ai/modals-chat/gemini/Gemini-pro.ts +0 -203
- package/lib/ai/modals-chat/gemini/config.ts +0 -11
- package/lib/ai/modals-chat/gemini/geminiFast.ts +0 -169
- package/lib/canvas/utils/bg.ts +0 -120
- package/lib/canvas/utils/circular.ts +0 -17
- package/lib/canvas/utils/imageProperties.ts +0 -418
- package/lib/canvas/utils/radius.ts +0 -26
- /package/dist/cjs/canvas/utils/{charts.js → Charts/charts.js} +0 -0
- /package/dist/cjs/canvas/utils/{customLines.js → Custom/customLines.js} +0 -0
- /package/dist/cjs/canvas/utils/{conversion.d.ts → General/conversion.d.ts} +0 -0
- /package/dist/cjs/canvas/utils/{conversion.js → General/conversion.js} +0 -0
- /package/dist/cjs/canvas/utils/{textProperties.js → Texts/textProperties.js} +0 -0
- /package/dist/esm/canvas/utils/{charts.js → Charts/charts.js} +0 -0
- /package/dist/esm/canvas/utils/{customLines.js → Custom/customLines.js} +0 -0
- /package/dist/esm/canvas/utils/{conversion.d.ts → General/conversion.d.ts} +0 -0
- /package/dist/esm/canvas/utils/{conversion.js → General/conversion.js} +0 -0
- /package/dist/esm/canvas/utils/{textProperties.js → Texts/textProperties.js} +0 -0
|
@@ -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
|
-
}
|
package/lib/canvas/utils/bg.ts
DELETED
|
@@ -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
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Applies a circular border to the canvas context.
|
|
3
|
-
* @param ctx The canvas rendering context.
|
|
4
|
-
* @param width The width of the canvas.
|
|
5
|
-
* @param height The height of the canvas.
|
|
6
|
-
* @param radius The radius of the circular border.
|
|
7
|
-
* @returns A void.
|
|
8
|
-
*/
|
|
9
|
-
export function circularBorder(ctx: any, width: number, height: number, radius: number = 0): void {
|
|
10
|
-
const minDimension = Math.min(width, height);
|
|
11
|
-
const clipRadius = minDimension / 2 + radius;
|
|
12
|
-
ctx.save();
|
|
13
|
-
ctx.beginPath();
|
|
14
|
-
ctx.arc(width / 2, height / 2, clipRadius, 0, Math.PI * 2);
|
|
15
|
-
ctx.closePath();
|
|
16
|
-
ctx.clip();
|
|
17
|
-
}
|