apexify.js 4.0.7 → 4.0.8
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/ai/ApexAI.d.ts +5 -7
- package/dist/ai/ApexAI.d.ts.map +1 -1
- package/dist/ai/ApexAI.js +28 -6
- package/dist/ai/ApexAI.js.map +1 -1
- package/dist/ai/functions/draw.js.map +1 -1
- package/dist/ai/modals-chat/Gemini-flash.d.ts +8 -1
- package/dist/ai/modals-chat/Gemini-flash.d.ts.map +1 -1
- package/dist/ai/modals-chat/Gemini-flash.js +118 -51
- package/dist/ai/modals-chat/Gemini-flash.js.map +1 -1
- package/dist/ai/modals-chat/Gemini-pro.d.ts +8 -1
- package/dist/ai/modals-chat/Gemini-pro.d.ts.map +1 -1
- package/dist/ai/modals-chat/Gemini-pro.js +115 -51
- package/dist/ai/modals-chat/Gemini-pro.js.map +1 -1
- package/lib/ai/ApexAI.ts +42 -15
- package/lib/ai/functions/draw.ts +1 -1
- package/lib/ai/modals-chat/Gemini-flash.ts +140 -52
- package/lib/ai/modals-chat/Gemini-pro.ts +139 -53
- package/package.json +3 -2
|
@@ -9,11 +9,27 @@ const path_1 = __importDefault(require("path"));
|
|
|
9
9
|
const fs_1 = __importDefault(require("fs"));
|
|
10
10
|
const config_1 = __importDefault(require("./config"));
|
|
11
11
|
const general_functions_1 = require("../../canvas/utils/general functions");
|
|
12
|
+
const verse_db_1 = require("verse.db");
|
|
13
|
+
const axios_1 = __importDefault(require("axios"));
|
|
12
14
|
let currentApiKeyIndex = 0;
|
|
13
15
|
async function geminiPro(message, AI) {
|
|
14
|
-
var _a;
|
|
16
|
+
var _a, _b, _c, _d, _e;
|
|
15
17
|
try {
|
|
16
|
-
|
|
18
|
+
let apiKeyIndex = currentApiKeyIndex;
|
|
19
|
+
let genAI;
|
|
20
|
+
while (apiKeyIndex < config_1.default.apiKeys.length) {
|
|
21
|
+
const validateKey = await axios_1.default.get(`https://generativelanguage.googleapis.com/v1beta/models?key=${config_1.default.apiKeys[apiKeyIndex]}`);
|
|
22
|
+
if (validateKey.status === 200) {
|
|
23
|
+
genAI = new generative_ai_1.GoogleGenerativeAI(config_1.default.apiKeys[apiKeyIndex]);
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
apiKeyIndex++;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (apiKeyIndex === config_1.default.apiKeys.length) {
|
|
31
|
+
return 'All provided API keys are invalid.';
|
|
32
|
+
}
|
|
17
33
|
let personalityString = '';
|
|
18
34
|
if (AI.AiPersonality) {
|
|
19
35
|
const personalityFilePath = path_1.default.join(process.cwd(), AI.AiPersonality);
|
|
@@ -23,47 +39,77 @@ async function geminiPro(message, AI) {
|
|
|
23
39
|
const generationConfig = {
|
|
24
40
|
maxOutputTokens: 750,
|
|
25
41
|
};
|
|
26
|
-
const
|
|
27
|
-
|
|
42
|
+
const safetySettings = [
|
|
43
|
+
{
|
|
44
|
+
category: generative_ai_1.HarmCategory.HARM_CATEGORY_HARASSMENT,
|
|
45
|
+
threshold: generative_ai_1.HarmBlockThreshold.BLOCK_ONLY_HIGH,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
category: generative_ai_1.HarmCategory.HARM_CATEGORY_HATE_SPEECH,
|
|
49
|
+
threshold: generative_ai_1.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
category: generative_ai_1.HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
|
|
53
|
+
threshold: generative_ai_1.HarmBlockThreshold.BLOCK_LOW_AND_ABOVE,
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
category: generative_ai_1.HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
|
|
57
|
+
threshold: generative_ai_1.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
|
|
58
|
+
},
|
|
59
|
+
];
|
|
60
|
+
const systemInstruction = `${personalityString}\n And working on discord in serverName: ${message.serverName} at channelName: ${message.channelName} and responding to the userName:<@ ${message.userId}>`;
|
|
61
|
+
const model = genAI.getGenerativeModel({ model: "gemini-1.5-pro-latest", systemInstruction, generationConfig, safetySettings });
|
|
62
|
+
let historyData = undefined;
|
|
63
|
+
const defaultHistory = [
|
|
64
|
+
{
|
|
65
|
+
role: "user",
|
|
66
|
+
parts: [{ text: `${personalityString}\n And working on discord in serverName: ${message.serverName} at channelName: ${message.channelName} and responding to the userName: <@${message.userId}>` }],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
role: "model",
|
|
70
|
+
parts: [{ text: `I will greet the user with their name: <@${message.userId}>. Feel free to ask me anything! 😊` }],
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
role: "user",
|
|
74
|
+
parts: [{ text: "Any question regarding JEDI STUDIO, verse.db, apexify.js, or djs-builder?" }],
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
role: "model",
|
|
78
|
+
parts: [{ text: `You should reply with visiting documentation online at jedi-studio.com. The development team consists of 8 people, led by Marco. The CEO/founder is Kimo.` }],
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
role: "user",
|
|
82
|
+
parts: [{ text: "How was I developed or programmed?" }],
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
role: "model",
|
|
86
|
+
parts: [{ text: `You were made by JEDI STUDIO under the development of jedi.tsx, one of the CEOs for JEDI STUDIO.` }],
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
role: "user",
|
|
90
|
+
parts: [{ text: "Tell me about verse.db." }],
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
role: "model",
|
|
94
|
+
parts: [{ text: `verse.db is a database that enables users to manage data for SQL, JSON, YAML, and SQOL. It's a new brand by JEDI STUDIO, and SOOL will support more database management with comprehensive features and security.` }],
|
|
95
|
+
},
|
|
96
|
+
];
|
|
97
|
+
let db;
|
|
98
|
+
if (message.db) {
|
|
99
|
+
db = new verse_db_1.connect({ adapter: 'json', dataPath: `${message.serverId}_ChatHistory` });
|
|
100
|
+
const data = await db.find(`${message.userId}_chatHistory`, { userId: message.userId });
|
|
101
|
+
if (!((_a = data.results) === null || _a === void 0 ? void 0 : _a.history) || ((_c = (_b = data.results) === null || _b === void 0 ? void 0 : _b.history) === null || _c === void 0 ? void 0 : _c.length) === 0) {
|
|
102
|
+
await db.update(`${message.userId}_chatHistory`, { userId: message.userId }, { $set: { history: [] } }, true);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
historyData = ((_d = data.results) === null || _d === void 0 ? void 0 : _d.history) || undefined;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
28
108
|
const chat = model.startChat({
|
|
29
|
-
history:
|
|
30
|
-
{
|
|
31
|
-
role: "user",
|
|
32
|
-
parts: [{ text: `${personalityString}\n And working on discord in serverName: ${message.guild.name} at channelName: ${message.channel.name} and responding to the userName: ${message.author.username}` }],
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
role: "model",
|
|
36
|
-
parts: [{ text: `I will greet the user with their name: <@${message.author.id}>. Feel free to ask me anything! 😊` }],
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
role: "user",
|
|
40
|
-
parts: [{ text: "Any question regarding JEDI STUDIO, verse.db, apexify.js, or djs-builder?" }],
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
role: "model",
|
|
44
|
-
parts: [{ text: `You should reply with visiting documentation online at jedi-studio.com. The development team consists of 8 people, led by Marco. The CEO/founder is Kimo.` }],
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
role: "user",
|
|
48
|
-
parts: [{ text: "How was I developed or programmed?" }],
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
role: "model",
|
|
52
|
-
parts: [{ text: `You were made by JEDI STUDIO under the development of jedi.tsx, one of the CEOs for JEDI STUDIO.` }],
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
role: "user",
|
|
56
|
-
parts: [{ text: "Tell me about verse.db." }],
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
role: "model",
|
|
60
|
-
parts: [{ text: `verse.db is a database that enables users to manage data for SQL, JSON, YAML, and SQOL. It's a new brand by JEDI STUDIO, and SOOL will support more database management with comprehensive features and security.` }],
|
|
61
|
-
},
|
|
62
|
-
],
|
|
109
|
+
history: historyData || defaultHistory,
|
|
63
110
|
generationConfig
|
|
64
111
|
});
|
|
65
|
-
const
|
|
66
|
-
const imgURL = (attachment === null || attachment === void 0 ? void 0 : attachment.url) || null;
|
|
112
|
+
const imgURL = ((_e = message.attachment) === null || _e === void 0 ? void 0 : _e.url) || null;
|
|
67
113
|
let result;
|
|
68
114
|
if (imgURL) {
|
|
69
115
|
const imageData = await urlToBase64(imgURL);
|
|
@@ -78,22 +124,40 @@ async function geminiPro(message, AI) {
|
|
|
78
124
|
else {
|
|
79
125
|
result = await chat.sendMessage(AI.userMsg);
|
|
80
126
|
}
|
|
81
|
-
const response = result.response;
|
|
82
|
-
|
|
127
|
+
const response = await result.response.text();
|
|
128
|
+
if (message.db) {
|
|
129
|
+
const updateQuery_1 = {
|
|
130
|
+
$push: {
|
|
131
|
+
"history": {
|
|
132
|
+
role: "user",
|
|
133
|
+
parts: [{ text: `${AI.userMsg}` }]
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
historyData = await db.update(`${message.userId}_chatHistory`, { userId: message.userId }, updateQuery_1, true);
|
|
138
|
+
const updateQuery_2 = {
|
|
139
|
+
$push: {
|
|
140
|
+
"history": {
|
|
141
|
+
role: "model",
|
|
142
|
+
parts: [{ text: `${response}` }]
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
historyData = await db.update(`${message.userId}_chatHistory`, { userId: message.userId }, updateQuery_2, true);
|
|
147
|
+
}
|
|
148
|
+
return response;
|
|
83
149
|
}
|
|
84
150
|
catch (e) {
|
|
85
151
|
if (e.message) {
|
|
86
152
|
if (e.message === '[GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1/models/gemini-pro:generateContent: [400 Bad Request] User location is not supported for the API use.') {
|
|
87
|
-
return
|
|
153
|
+
return `The hoster/bot owner/the used host isn't supported by gemini.`;
|
|
154
|
+
}
|
|
155
|
+
else if (e.response && (e.response.status === 429 || e.response.status === 403)) {
|
|
156
|
+
return 'Ai is on a cooldown for the rest of the day. Either provide your own API key or wait for tomorrow. Check ai.google.dev for free apikeys';
|
|
88
157
|
}
|
|
89
|
-
else if (e.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return geminiPro(message, { ...AI, API_KEY: config_1.default.apiKeys[currentApiKeyIndex] });
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
return 'Ai is on a cooldown for the rest of the day. Either provide your API key or wait for tomorrow. Check ai.google.dev for apikeys';
|
|
96
|
-
}
|
|
158
|
+
else if (e.message === '[GoogleGenerativeAI Error]: Candidate was blocked due to SAFETY') {
|
|
159
|
+
console.error(e);
|
|
160
|
+
return `Due to safety enabled by gemini you have been blocked.`;
|
|
97
161
|
}
|
|
98
162
|
else {
|
|
99
163
|
console.error(e);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Gemini-pro.js","sourceRoot":"","sources":["../../../lib/ai/modals-chat/Gemini-pro.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"Gemini-pro.js","sourceRoot":"","sources":["../../../lib/ai/modals-chat/Gemini-pro.ts"],"names":[],"mappings":";;;;;;AAAA,yDAA6F;AAC7F,gDAAwB;AACxB,4CAAoB;AACpB,sDAA8B;AAC9B,4EAAiE;AACjE,uCAAoC;AACpC,kDAA0B;AAE1B,IAAI,kBAAkB,GAAG,CAAC,CAAC;AAEpB,KAAK,UAAU,SAAS,CAAC,OAAqH,EAAE,EAA6E;;IAGlO,IAAI,CAAC;QAEH,IAAI,WA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/ai/ApexAI.ts
CHANGED
|
@@ -22,9 +22,6 @@ import { imageTools } from "./buttons/drawMenu";
|
|
|
22
22
|
import { ImageModals } from './functions/validOptions';
|
|
23
23
|
import { apexai, geminiFlash, geminiPro, facebook_ai, yi_34b, starChat } from "./modals-chat/modals";
|
|
24
24
|
|
|
25
|
-
/**
|
|
26
|
-
* Configuration options for the Gemini Flash functionality.
|
|
27
|
-
*/
|
|
28
25
|
export interface Options {
|
|
29
26
|
/**
|
|
30
27
|
* Configuration options related to voice functionality.
|
|
@@ -106,8 +103,8 @@ export interface Options {
|
|
|
106
103
|
personality?: string | any;
|
|
107
104
|
API_KEY?: string;
|
|
108
105
|
memory?: {
|
|
109
|
-
memoryOn
|
|
110
|
-
id
|
|
106
|
+
memoryOn?: boolean;
|
|
107
|
+
id?: string;
|
|
111
108
|
};
|
|
112
109
|
typeWriting?: {
|
|
113
110
|
enable?: boolean;
|
|
@@ -138,8 +135,9 @@ export interface Options {
|
|
|
138
135
|
*/
|
|
139
136
|
others?: {
|
|
140
137
|
messageType?: {
|
|
141
|
-
type
|
|
142
|
-
intialContent
|
|
138
|
+
type?: string;
|
|
139
|
+
intialContent?: string;
|
|
140
|
+
sendAs?: string | "embed" | "content";
|
|
143
141
|
};
|
|
144
142
|
buttons?: any[];
|
|
145
143
|
keywords?: string[];
|
|
@@ -275,7 +273,7 @@ export async function ApexAI (message: any, aiOptions: Options) {
|
|
|
275
273
|
|
|
276
274
|
await message.channel?.sendTyping();
|
|
277
275
|
|
|
278
|
-
|
|
276
|
+
usermsg = message.content;
|
|
279
277
|
|
|
280
278
|
if (
|
|
281
279
|
message.attachments.some((attachment: any) =>
|
|
@@ -319,10 +317,10 @@ export async function ApexAI (message: any, aiOptions: Options) {
|
|
|
319
317
|
if (message.attachments.size > 0) {
|
|
320
318
|
if (attachment.name.endsWith('.pdf')) {
|
|
321
319
|
const pdfContent = await readPdf(attachment.url);
|
|
322
|
-
usermsg += pdfContent
|
|
320
|
+
usermsg += `\n\n This is the pdf file content:\n\n ${pdfContent}`;
|
|
323
321
|
} else {
|
|
324
322
|
const txtContent = await readTextFile(attachment.url);
|
|
325
|
-
usermsg += txtContent
|
|
323
|
+
usermsg += `\n\n This is the .txt file content:\n\n ${txtContent}`;
|
|
326
324
|
}
|
|
327
325
|
}
|
|
328
326
|
}
|
|
@@ -390,9 +388,10 @@ export async function ApexAI (message: any, aiOptions: Options) {
|
|
|
390
388
|
|
|
391
389
|
if (drawValid) {
|
|
392
390
|
|
|
393
|
-
usermsg = `Rewrite this text below in more descriptive way make it clear to be visualized correctly and enhance it and use stronger words please\n\n\n ${usermsg}`
|
|
394
|
-
|
|
395
|
-
|
|
391
|
+
usermsg = `Rewrite this text below in more descriptive way make it clear to be visualized correctly and enhance it and use stronger words please and please return the response with nothing else in just the enhanced prompt nothing more nothing less\n\n\n ${usermsg}`
|
|
392
|
+
|
|
393
|
+
if (enhancerOn) {
|
|
394
|
+
usermsg += await hercai.question({ model: "v3", content: usermsg});
|
|
396
395
|
}
|
|
397
396
|
|
|
398
397
|
return await aiImagine(
|
|
@@ -456,9 +455,37 @@ export async function ApexAI (message: any, aiOptions: Options) {
|
|
|
456
455
|
} else if (chatModal === 'starChat') {
|
|
457
456
|
response = await starChat(usermsg);
|
|
458
457
|
} else if (chatModal === 'gemini-flash') {
|
|
459
|
-
response = await geminiFlash(
|
|
458
|
+
response = await geminiFlash(
|
|
459
|
+
{
|
|
460
|
+
userId: message.author.id,
|
|
461
|
+
serverName: message.guild.name,
|
|
462
|
+
serverId: message.guild.id,
|
|
463
|
+
channelName: message.channel.name,
|
|
464
|
+
attachment: attachment,
|
|
465
|
+
db: memoryOn
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
userMsg: usermsg,
|
|
469
|
+
API_KEY: API_KEY,
|
|
470
|
+
AiPersonality: personality
|
|
471
|
+
}
|
|
472
|
+
);
|
|
460
473
|
} else if (chatModal === 'gemini-pro') {
|
|
461
|
-
response = await geminiPro(
|
|
474
|
+
response = await geminiPro(
|
|
475
|
+
{
|
|
476
|
+
userId: message.author.id,
|
|
477
|
+
serverName: message.guild.name,
|
|
478
|
+
serverId: message.guild.id,
|
|
479
|
+
channelName: message.channel.name,
|
|
480
|
+
attachment: attachment,
|
|
481
|
+
db: memoryOn
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
userMsg: usermsg,
|
|
485
|
+
API_KEY: API_KEY,
|
|
486
|
+
AiPersonality: personality
|
|
487
|
+
}
|
|
488
|
+
);
|
|
462
489
|
} else if (chatModal === 'v3' || chatModal === 'v3-32k' || chatModal === 'turbo' || chatModal === 'turbo-16k' || chatModal === 'gemini') {
|
|
463
490
|
if (!memoryOn) {
|
|
464
491
|
|
package/lib/ai/functions/draw.ts
CHANGED
|
@@ -1,17 +1,40 @@
|
|
|
1
|
-
import { GoogleGenerativeAI } from "@google/generative-ai";
|
|
1
|
+
import { GoogleGenerativeAI, HarmCategory, HarmBlockThreshold } from "@google/generative-ai";
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import config from './config';
|
|
5
5
|
import { converter } from "../../canvas/utils/general functions";
|
|
6
|
+
import { connect } from "verse.db";
|
|
7
|
+
import axios from "axios";
|
|
6
8
|
|
|
7
9
|
let currentApiKeyIndex = 0;
|
|
8
10
|
|
|
9
|
-
export async function geminiFlash(message: any, AI: { AiPersonality: string | null, userMsg: string, API_KEY: string | null }): Promise<any> {
|
|
11
|
+
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> {
|
|
12
|
+
|
|
13
|
+
let db: any;
|
|
14
|
+
|
|
15
|
+
if (message.db) {
|
|
16
|
+
db = new connect({ adapter: 'json', dataPath: `${message.serverId}_ChatHistory` });
|
|
17
|
+
}
|
|
10
18
|
|
|
11
19
|
try {
|
|
12
|
-
|
|
20
|
+
let apiKeyIndex = currentApiKeyIndex;
|
|
21
|
+
let genAI: any;
|
|
22
|
+
while (apiKeyIndex < config.apiKeys.length) {
|
|
23
|
+
const validateKey = await axios.get(`https://generativelanguage.googleapis.com/v1beta/models?key=${config.apiKeys[apiKeyIndex]}`);
|
|
24
|
+
if (validateKey.status === 200) {
|
|
25
|
+
genAI = new GoogleGenerativeAI(config.apiKeys[apiKeyIndex]);
|
|
26
|
+
|
|
27
|
+
break;
|
|
28
|
+
} else {
|
|
29
|
+
apiKeyIndex++;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
13
32
|
|
|
33
|
+
if (apiKeyIndex === config.apiKeys.length) {
|
|
34
|
+
return 'All provided API keys are invalid.';
|
|
35
|
+
}
|
|
14
36
|
let personalityString: string = '';
|
|
37
|
+
|
|
15
38
|
if (AI.AiPersonality) {
|
|
16
39
|
const personalityFilePath = path.join(process.cwd(), AI.AiPersonality);
|
|
17
40
|
const personalityContent = fs.readFileSync(personalityFilePath, 'utf-8');
|
|
@@ -22,49 +45,83 @@ export async function geminiFlash(message: any, AI: { AiPersonality: string | nu
|
|
|
22
45
|
maxOutputTokens: 750,
|
|
23
46
|
};
|
|
24
47
|
|
|
25
|
-
const
|
|
26
|
-
|
|
48
|
+
const safetySettings = [
|
|
49
|
+
{
|
|
50
|
+
category: HarmCategory.HARM_CATEGORY_HARASSMENT,
|
|
51
|
+
threshold: HarmBlockThreshold.BLOCK_ONLY_HIGH,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
|
|
55
|
+
threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
|
|
59
|
+
threshold: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE,
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
|
|
63
|
+
threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
|
|
64
|
+
},
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
const systemInstruction = `${personalityString}\n And working on discord in serverName: ${message.serverName} at channelName: ${message.channelName} and responding to the userName: <@${message.userId}>`;
|
|
68
|
+
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash-latest", systemInstruction, generationConfig, safetySettings });
|
|
69
|
+
|
|
70
|
+
const defaultHistory = [
|
|
71
|
+
{
|
|
72
|
+
role: "user",
|
|
73
|
+
parts: [{ text: `${personalityString}\n And working on discord in serverName: ${message.serverName} at channelName: ${message.channelName} and responding to the userName: <@${message.userId}>` }],
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
role: "model",
|
|
77
|
+
parts: [{ text: `I will greet the user with their name: <@${message.userId}>. Feel free to ask me anything! 😊` }],
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
role: "user",
|
|
81
|
+
parts: [{ text: "Any question regarding JEDI STUDIO, verse.db, apexify.js, or djs-builder?" }],
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
role: "model",
|
|
85
|
+
parts: [{ text: `You should reply with visiting documentation online at jedi-studio.com. The development team consists of 8 people, led by Marco. The CEO/founder is Kimo.` }],
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
role: "user",
|
|
89
|
+
parts: [{ text: "How was I developed or programmed?" }],
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
role: "model",
|
|
93
|
+
parts: [{ text: `You were made by JEDI STUDIO under the development of jedi.tsx, one of the CEOs for JEDI STUDIO.` }],
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
role: "user",
|
|
97
|
+
parts: [{ text: "Tell me about verse.db." }],
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
role: "model",
|
|
101
|
+
parts: [{ text: `verse.db is a database that enables users to manage data for SQL, JSON, YAML, and SQOL. It's a new brand by JEDI STUDIO, and SOOL will support more database management with comprehensive features and security.` }],
|
|
102
|
+
},
|
|
103
|
+
];
|
|
104
|
+
|
|
105
|
+
let historyData: any[] | undefined = undefined;
|
|
106
|
+
|
|
107
|
+
if (message.db) {
|
|
108
|
+
db = new connect({ adapter: 'json', dataPath: `${message.serverId}_ChatHistory` });
|
|
109
|
+
|
|
110
|
+
const data = await db.find(`${message.userId}_chatHistory`, { userId: message.userId });
|
|
111
|
+
|
|
112
|
+
if (!data.results?.history || data.results?.history?.length === 0) {
|
|
113
|
+
await db.update(`${message.userId}_chatHistory`, { userId: message.userId }, { $set: { history: [] } }, true);
|
|
114
|
+
} else {
|
|
115
|
+
historyData = data.results?.history || undefined;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
27
118
|
|
|
28
119
|
const chat = model.startChat({
|
|
29
|
-
history:
|
|
30
|
-
{
|
|
31
|
-
role: "user",
|
|
32
|
-
parts: [{ text: `${personalityString}\n And working on discord in serverName: ${message.guild.name} at channelName: ${message.channel.name} and responding to the userName: ${message.author.username}` }],
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
role: "model",
|
|
36
|
-
parts: [{ text: `I will greet the user with their name: <@${message.author.id}>. Feel free to ask me anything! 😊` }],
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
role: "user",
|
|
40
|
-
parts: [{ text: "Any question regarding JEDI STUDIO, verse.db, apexify.js, or djs-builder?" }],
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
role: "model",
|
|
44
|
-
parts: [{ text: `You should reply with visiting documentation online at jedi-studio.com. The development team consists of 8 people, led by Marco. The CEO/founder is Kimo.` }],
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
role: "user",
|
|
48
|
-
parts: [{ text: "How was I developed or programmed?" }],
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
role: "model",
|
|
52
|
-
parts: [{ text: `You were made by JEDI STUDIO under the development of jedi.tsx, one of the CEOs for JEDI STUDIO.` }],
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
role: "user",
|
|
56
|
-
parts: [{ text: "Tell me about verse.db." }],
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
role: "model",
|
|
60
|
-
parts: [{ text: `verse.db is a database that enables users to manage data for SQL, JSON, YAML, and SQOL. It's a new brand by JEDI STUDIO, and SOOL will support more database management with comprehensive features and security.` }],
|
|
61
|
-
},
|
|
62
|
-
],
|
|
120
|
+
history: historyData || defaultHistory,
|
|
63
121
|
generationConfig
|
|
64
|
-
|
|
122
|
+
});
|
|
65
123
|
|
|
66
|
-
const
|
|
67
|
-
const imgURL = attachment?.url || null;
|
|
124
|
+
const imgURL = message.attachment?.url || null;
|
|
68
125
|
let result: any;
|
|
69
126
|
|
|
70
127
|
if (imgURL) {
|
|
@@ -79,20 +136,51 @@ export async function geminiFlash(message: any, AI: { AiPersonality: string | nu
|
|
|
79
136
|
} else {
|
|
80
137
|
result = await chat.sendMessage(AI.userMsg);
|
|
81
138
|
}
|
|
82
|
-
const response = result.response;
|
|
83
139
|
|
|
84
|
-
|
|
140
|
+
const response = await result.response.text();
|
|
141
|
+
|
|
142
|
+
if (message.db) {
|
|
143
|
+
|
|
144
|
+
const updateQuery_1 = {
|
|
145
|
+
$push: {
|
|
146
|
+
"history": {
|
|
147
|
+
role: "user",
|
|
148
|
+
parts: [{ text: `${AI.userMsg}` }]
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
historyData = await db.update(`${message.userId}_chatHistory`,
|
|
154
|
+
{ userId: message.userId },
|
|
155
|
+
updateQuery_1, true
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
const updateQuery_2 = {
|
|
159
|
+
$push: {
|
|
160
|
+
"history": {
|
|
161
|
+
role: "model",
|
|
162
|
+
parts: [{ text: `${response}` }]
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
historyData = await db.update(`${message.userId}_chatHistory`,
|
|
168
|
+
{ userId: message.userId },
|
|
169
|
+
updateQuery_2,
|
|
170
|
+
true
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return response;
|
|
85
175
|
} catch (e: any) {
|
|
86
176
|
if (e.message) {
|
|
87
177
|
if (e.message === '[GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1/models/gemini-pro:generateContent: [400 Bad Request] User location is not supported for the API use.') {
|
|
88
|
-
return
|
|
89
|
-
} else if (e.response && (e.response.status === 429 || e.response.status ===
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return 'Ai is on a cooldown for the rest of the day. Either provide your API key or wait for tomorrow. Check ai.google.dev for apikeys';
|
|
95
|
-
}
|
|
178
|
+
return `The hoster/bot owner/the used host isn't supported by gemini.`;
|
|
179
|
+
} else if (e.response && (e.response.status === 429 || e.response.status === 403)) {
|
|
180
|
+
return 'Ai is on a cooldown for the rest of the day. Either provide your own API key or wait for tomorrow. Check ai.google.dev for free apikeys';
|
|
181
|
+
} else if (e.message === '[GoogleGenerativeAI Error]: Candidate was blocked due to SAFETY') {
|
|
182
|
+
console.error(e);
|
|
183
|
+
return `Due to safety enabled by gemini you have been blocked.`;
|
|
96
184
|
} else {
|
|
97
185
|
console.error(e);
|
|
98
186
|
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.`;
|