fix(all): TRUE multicloud.

This commit is contained in:
Rodrigo Rodriguez 2024-08-29 22:10:52 -03:00
parent 7d459d5579
commit 3952724f7a
11 changed files with 98 additions and 57 deletions

1
.vscode/launch.json vendored
View file

@ -14,6 +14,7 @@
"NODE_NO_WARNINGS":"1"
},
"args": [
"--max-old-space-size 5120",
"--no-deprecation",
"--loader ts-node/esm",
"--require ${workspaceRoot}/suppress-node-warnings.cjs",

View file

@ -124,7 +124,7 @@
"cli-progress": "3.12.0",
"cli-spinner": "0.2.10",
"core-js": "3.37.1",
"csv-database": "^0.9.2",
"csv-database": "0.9.2",
"data-forge": "1.10.2",
"date-diff": "1.0.2",
"docximager": "0.0.4",

View file

@ -65,6 +65,7 @@ import { GBLogEx } from './GBLogEx.js';
import { GBDeployer } from './GBDeployer.js';
import { SystemKeywords } from '../../basic.gblib/services/SystemKeywords.js';
import { DialogKeywords } from '../../basic.gblib/services/DialogKeywords.js';
import csvdb from 'csv-database';
/**
* GBCoreService contains main logic for handling storage services related
@ -136,8 +137,6 @@ export class GBCoreService implements IGBCoreService {
if (!Fs.existsSync(storage)) {
process.env.STORAGE_SYNC = 'true';
}
} else {
throw new Error(`Unknown dialect: ${this.dialect}.`);
}
@ -519,8 +518,7 @@ ENDPOINT_UPDATE=true
* Verifies that an complex global password has been specified
* before starting the server.
*/
public ensureAdminIsSecured() {
}
public ensureAdminIsSecured() {}
public async createBootInstance(
core: GBCoreService,
@ -672,6 +670,7 @@ ENDPOINT_UPDATE=true
}
public async setConfig(min, name: string, value: any): Promise<any> {
if (GBConfigService.get('STORAGE_NAME')) {
// Handles calls for BASIC persistence on sheet files.
GBLog.info(`Defining Config.xlsx variable ${name}= '${value}'...`);
@ -715,6 +714,17 @@ ENDPOINT_UPDATE=true
`${baseUrl}/drive/items/${document.id}/workbook/worksheets('${sheets.value[0].name}')/range(address='${address}')`
)
.patch(body);
} else {
let path = DialogKeywords.getGBAIPath(min.botId, `gbot`);
const config = Path.join(GBConfigService.get('STORAGE_LIBRARY'), path, 'config.csv');
const db = await csvdb(config, ['name', 'value'], ',');
if (await db.get({ name: name })) {
await db.edit({ name: name }, { name, value });
} else {
await db.add({ name, value });
}
}
}
/**
@ -775,7 +785,7 @@ ENDPOINT_UPDATE=true
}
if (!value && platform) {
value = process.env[name.replace(/ /g, "_").toUpperCase()];
value = process.env[name.replace(/ /g, '_').toUpperCase()];
}
if (value && typeof defaultValue === 'boolean') {
@ -822,9 +832,7 @@ ENDPOINT_UPDATE=true
const files = Fs.readdirSync(libraryPath);
await CollectionUtil.asyncForEach(files, async file => {
if (file.trim().toLowerCase() !== 'default.gbai') {
let botId = file.replace(/\.gbai/, '');
await this.syncBotStorage(instances, botId, deployer, libraryPath);
@ -836,7 +844,6 @@ ENDPOINT_UPDATE=true
let instance = instances.find(p => p.botId.toLowerCase().trim() === botId.toLowerCase().trim());
if (!instance) {
GBLog.info(`Importing package ${botId}...`);
// Creates a bot.
@ -848,7 +855,6 @@ ENDPOINT_UPDATE=true
const gbaiPath = Path.join(libraryPath, `${botId}.gbai`);
if (!Fs.existsSync(gbaiPath)) {
Fs.mkdirSync(gbaiPath, { recursive: true });
const base = Path.join(process.env.PWD, 'templates', 'default.gbai');
@ -876,7 +882,7 @@ ENDPOINT_UPDATE=true
Fs.cpSync(Path.join(base, `default.gbdialog`), Path.join(gbaiPath, `default.gbdialog`), {
errorOnExist: false,
force: true,
recursive: true,
recursive: true
});
Fs.cpSync(Path.join(base, `default.gbdrive`), Path.join(gbaiPath, `default.gbdrive`), {
errorOnExist: false,

View file

@ -324,10 +324,20 @@ export class GBDeployer implements IGBDeployer {
public async loadOrCreateEmptyVectorStore(min: GBMinInstance): Promise<HNSWLib> {
let vectorStore: HNSWLib;
const azureOpenAIKey = await min.core.getParam(min.instance, 'Azure Open AI Key', null);
const azureOpenAIVersion = await min.core.getParam(min.instance, 'Azure Open AI Version', null);
const azureOpenAIApiInstanceName = await min.core.getParam(min.instance, 'Azure Open AI Instance', null);
const azureOpenAIEmbeddingModel = await min.core.getParam(min.instance, 'Azure Open AI Embedding Model', null);
const azureOpenAIKey = await (min.core as any)['getParam'](min.instance, 'Azure Open AI Key', null, true);
const azureOpenAIVersion = await (min.core as any)['getParam'](min.instance, 'Azure Open AI Version', null, true);
const azureOpenAIApiInstanceName = await (min.core as any)['getParam'](
min.instance,
'Azure Open AI Instance',
null,
true
);
const azureOpenAIEmbeddingModel = await (min.core as any)['getParam'](
min.instance,
'Azure Open AI Embedding Model',
null,
true
);
let embedding;
if (!azureOpenAIEmbeddingModel) {
@ -663,6 +673,10 @@ export class GBDeployer implements IGBDeployer {
// Updates instance object.
await this.core.saveInstance(min.instance);
GBLogEx.info(min, `Reloading bot ${min.botId}...`);
GBServer.globals.minService.unmountBot(min.botId);
GBServer.globals.minService.mountBot(min.instance);
GBLogEx.info(min, `Bot ${min.botId} reloaded.`);
}
break;

View file

@ -827,7 +827,7 @@ export class GBMinService {
min.sandBoxMap = {};
min['scheduleMap'] = {};
min['conversationWelcomed'] = {};
if (await min.core.getParam(min.instance, 'Azure Open AI Instance', null)) {
if (await min.core.getParam(min.instance, 'Answer Mode', null)) {
const gbkbPath = DialogKeywords.getGBAIPath(min.botId, 'gbkb');
min['vectorStorePath'] = Path.join('work', gbkbPath, 'docs-vectorized');
min['vectorStore'] = await this.deployer.loadOrCreateEmptyVectorStore(min);

View file

@ -54,6 +54,7 @@ import { RecursiveCharacterTextSplitter } from 'langchain/text_splitter';
import { Document } from 'langchain/document';
import getColors from 'get-image-colors';
import {
GBDialogStep,
GBLog,

View file

@ -0,0 +1,3 @@
name,value
Website,https://pragmatismo.cloud
Answer Mode,direct
1 name value
2 Website https://pragmatismo.cloud
3 Answer Mode direct

View file

@ -0,0 +1,6 @@
PARAM when
PARAM subject
DESCRIPTION Called when someone asks to save a quick meeting.
SAVE "reminders.csv", when, subject

View file

@ -0,0 +1,7 @@
REM SET SCHEDULER "1 * * * * "
data = FIND "reminder.csv", "when=" + hour
if (data) THEN
TALK TO admin, data.subject
end if

View file

@ -0,0 +1,3 @@
BEGIN SYSTEM PROMPT
You are a reminder AI assistant.
END SYSTEM PROMPT