fix(all): TRUE multicloud.

This commit is contained in:
Rodrigo Rodriguez 2024-08-29 19:53:56 -03:00
parent 21ed20dcf0
commit 7d459d5579
12 changed files with 160 additions and 109 deletions

View file

@ -782,7 +782,7 @@ export class DialogKeywords {
*/ */
public async getConfig({ pid, name }) { public async getConfig({ pid, name }) {
let { min, user, params } = await DialogKeywords.getProcessInfo(pid); let { min, user, params } = await DialogKeywords.getProcessInfo(pid);
return min.core.getParam(min.instance, name, null); return min.core.getParam(min.instance, name, null, false);
} }
/** /**

View file

@ -221,66 +221,8 @@ export class GBVMService extends GBService {
} }
} }
private syncStorageFromTABLE(folder: string, filename: string, min: GBMinInstance, mainName: string) { public static async loadConnections(min) {
const tablesFile = urlJoin(folder, `${filename}.tables.json`);
let sync = false;
if (Fs.existsSync(tablesFile)) {
const minBoot = GBServer.globals.minBoot;
const tableDef = JSON.parse(Fs.readFileSync(tablesFile, 'utf8')) as any;
const getTypeBasedOnCondition = (t, size) => {
if (1) {
switch (t) {
case 'string':
return `varchar(${size})`;
case 'guid':
return 'UUID';
case 'key':
return `varchar(${size})`;
case 'number':
return 'BIGINT';
case 'integer':
return 'INTEGER';
case 'double':
return 'FLOAT';
case 'float':
return 'FLOAT';
case 'date':
return 'DATE';
case 'boolean':
return 'BOOLEAN';
default:
return { type: 'TABLE', name: t };
}
} else {
switch (t) {
case 'string':
return { key: 'STRING' };
case 'guid':
return { key: 'UUID' };
case 'key':
return { key: 'STRING' }; // Assuming key is a string data type
case 'number':
return { key: 'BIGINT' };
case 'integer':
return { key: 'INTEGER' };
case 'double':
return { key: 'FLOAT' };
case 'float':
return { key: 'FLOAT' };
case 'date':
return { key: 'DATE' };
case 'boolean':
return { key: 'BOOLEAN' };
default:
return { key: 'TABLE', name: t };
}
}
};
const associations = [];
// Loads storage custom connections. // Loads storage custom connections.
const path = DialogKeywords.getGBAIPath(min.botId, null); const path = DialogKeywords.getGBAIPath(min.botId, null);
@ -343,6 +285,68 @@ export class GBVMService extends GBService {
min[connectionName]['gbconnection'] = con; min[connectionName]['gbconnection'] = con;
} }
}); });
}
private syncStorageFromTABLE(folder: string, filename: string, min: GBMinInstance, mainName: string) {
const tablesFile = urlJoin(folder, `${filename}.tables.json`);
let sync = false;
if (Fs.existsSync(tablesFile)) {
const minBoot = GBServer.globals.minBoot;
const tableDef = JSON.parse(Fs.readFileSync(tablesFile, 'utf8')) as any;
const getTypeBasedOnCondition = (t, size) => {
if (1) {
switch (t) {
case 'string':
return `varchar(${size})`;
case 'guid':
return 'UUID';
case 'key':
return `varchar(${size})`;
case 'number':
return 'BIGINT';
case 'integer':
return 'INTEGER';
case 'double':
return 'FLOAT';
case 'float':
return 'FLOAT';
case 'date':
return 'DATE';
case 'boolean':
return 'BOOLEAN';
default:
return { type: 'TABLE', name: t };
}
} else {
switch (t) {
case 'string':
return { key: 'STRING' };
case 'guid':
return { key: 'UUID' };
case 'key':
return { key: 'STRING' }; // Assuming key is a string data type
case 'number':
return { key: 'BIGINT' };
case 'integer':
return { key: 'INTEGER' };
case 'double':
return { key: 'FLOAT' };
case 'float':
return { key: 'FLOAT' };
case 'date':
return { key: 'DATE' };
case 'boolean':
return { key: 'BOOLEAN' };
default:
return { key: 'TABLE', name: t };
}
}
};
const associations = [];
const shouldSync = min.core.getParam<boolean>(min.instance, 'Synchronize Database', false); const shouldSync = min.core.getParam<boolean>(min.instance, 'Synchronize Database', false);
@ -1144,7 +1148,6 @@ export class GBVMService extends GBService {
}); });
const s = new VMScript(code, { filename: scriptPath }); const s = new VMScript(code, { filename: scriptPath });
result = vm1.run(s); result = vm1.run(s);
}); });
})(); })();
} else { } else {

View file

@ -724,7 +724,7 @@ ENDPOINT_UPDATE=true
* @param name Name of param to get from instance. * @param name Name of param to get from instance.
* @param defaultValue Value returned when no param is defined in Config.xlsx. * @param defaultValue Value returned when no param is defined in Config.xlsx.
*/ */
public getParam<T>(instance: IGBInstance, name: string, defaultValue?: T): any { public getParam<T>(instance: IGBInstance, name: string, defaultValue?: T, platform=false): any {
let value = null; let value = null;
let params; let params;
name = name.trim(); name = name.trim();
@ -774,6 +774,10 @@ ENDPOINT_UPDATE=true
value = null; value = null;
} }
if (!value && platform){
value = process.env[name.replace(/ /g, "_").toUpperCase()];
}
if (value && typeof defaultValue === 'boolean') { if (value && typeof defaultValue === 'boolean') {
return new Boolean(value ? value.toString().toLowerCase() === 'true' : defaultValue).valueOf(); return new Boolean(value ? value.toString().toLowerCase() === 'true' : defaultValue).valueOf();
} }

View file

@ -447,7 +447,7 @@ export class GBDeployer implements IGBDeployer {
rows.shift(); rows.shift();
} }
} else if (Fs.existsSync(csv)) { } else if (Fs.existsSync(csv)) {
await workbook.csv.readFile(filePath); await workbook.csv.readFile(csv);
let worksheet = workbook.worksheets[0]; // Assuming the CSV file has only one sheet let worksheet = workbook.worksheets[0]; // Assuming the CSV file has only one sheet
rows = worksheet.getSheetValues(); rows = worksheet.getSheetValues();
@ -636,12 +636,23 @@ export class GBDeployer implements IGBDeployer {
const connectionName = t.replace(strFind, ''); const connectionName = t.replace(strFind, '');
let con = {}; let con = {};
con['name'] = connectionName; con['name'] = connectionName;
con['storageDriver'] = min.core.getParam<string>(min.instance, `${connectionName} Driver`, null);
const storageName = min.core.getParam<string>(min.instance, `${connectionName} Name`, null);
let file = min.core.getParam<string>(min.instance, `${connectionName} File`, null);
if (storageName) {
con['storageName'] = storageName;
con['storageServer'] = min.core.getParam<string>(min.instance, `${connectionName} Server`, null); con['storageServer'] = min.core.getParam<string>(min.instance, `${connectionName} Server`, null);
con['storageUsername'] = min.core.getParam<string>(min.instance, `${connectionName} Username`, null); con['storageUsername'] = min.core.getParam<string>(min.instance, `${connectionName} Username`, null);
con['storageName'] = min.core.getParam<string>(min.instance, `${connectionName} Name`, null);
con['storagePort'] = min.core.getParam<string>(min.instance, `${connectionName} Port`, null); con['storagePort'] = min.core.getParam<string>(min.instance, `${connectionName} Port`, null);
con['storagePassword'] = min.core.getParam<string>(min.instance, `${connectionName} Password`, null); con['storagePassword'] = min.core.getParam<string>(min.instance, `${connectionName} Password`, null);
con['storageDriver'] = min.core.getParam<string>(min.instance, `${connectionName} Driver`, null); } else if (file) {
const path = DialogKeywords.getGBAIPath(min.botId, 'gbdata');
con['storageFile'] = Path.join(GBConfigService.get('STORAGE_LIBRARY'), path, file);
} else {
GBLogEx.debug(min, `No storage information found for ${connectionName}, missing storage name or file.`);
}
connections.push(con); connections.push(con);
}); });

View file

@ -377,8 +377,8 @@ export class GBMinService {
} }
res.end(); res.end();
}); });
GBLog.verbose(`GeneralBots(${instance.engineName}) listening on: ${url}.`);
GBLog.verbose(`GeneralBots(${instance.engineName}) listening on: ${url}.`);
// Generates MS Teams manifest. // Generates MS Teams manifest.
@ -390,6 +390,8 @@ export class GBMinService {
Fs.writeFileSync(packageTeams, data); Fs.writeFileSync(packageTeams, data);
} }
await GBVMService.loadConnections(min);
// Serves individual URL for each bot user interface. // Serves individual URL for each bot user interface.
if (process.env.DISABLE_WEB !== 'true') { if (process.env.DISABLE_WEB !== 'true') {

View file

@ -1061,7 +1061,7 @@ export class KBService implements IGBKBService {
let logo = await this.getLogoByPage(min, page); let logo = await this.getLogoByPage(min, page);
if (logo) { if (logo) {
path = DialogKeywords.getGBAIPath(min.botId); path = DialogKeywords.getGBAIPath(min.botId);
const logoPath = Path.join(process.env.PWD, 'work', path, 'cache');
const baseUrl = page.url().split('/').slice(0, 3).join('/'); const baseUrl = page.url().split('/').slice(0, 3).join('/');
logo = logo.startsWith('https') ? logo : urlJoin(baseUrl, logo); logo = logo.startsWith('https') ? logo : urlJoin(baseUrl, logo);

View file

@ -294,12 +294,21 @@ export class ChatServices {
let model; let model;
const azureOpenAIKey = await min.core.getParam(min.instance, 'Azure Open AI Key', null); const azureOpenAIKey = await (min.core as any)['getParam'](min.instance, 'Azure Open AI Key', null, true);
const azureOpenAIGPTModel = await min.core.getParam(min.instance, 'Azure Open AI GPT Model', null); const azureOpenAIGPTModel = await (min.core as any)['getParam'](
const azureOpenAIVersion = await min.core.getParam(min.instance, 'Azure Open AI Version', null); min.instance,
const azureOpenAIApiInstanceName = await min.core.getParam(min.instance, 'Azure Open AI Instance', null); 'Azure Open AI GPT Model',
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
);
if (azureOpenAIKey) {
model = new ChatOpenAI({ model = new ChatOpenAI({
azureOpenAIApiKey: azureOpenAIKey, azureOpenAIApiKey: azureOpenAIKey,
azureOpenAIApiInstanceName: azureOpenAIApiInstanceName, azureOpenAIApiInstanceName: azureOpenAIApiInstanceName,
@ -308,14 +317,6 @@ export class ChatServices {
temperature: 0, temperature: 0,
callbacks: [logHandler] callbacks: [logHandler]
}); });
} else {
model = new ChatOpenAI({
openAIApiKey: process.env.OPENAI_API_KEY,
modelName: 'gpt-3.5-turbo-0125',
temperature: 0,
callbacks: [logHandler]
});
}
let tools = await ChatServices.getTools(min); let tools = await ChatServices.getTools(min);
let toolsAsText = ChatServices.getToolsAsText(tools); let toolsAsText = ChatServices.getToolsAsText(tools);
@ -478,19 +479,22 @@ export class ChatServices {
const con = min[`llm`]['gbconnection']; const con = min[`llm`]['gbconnection'];
const dialect = con['storageDriver']; const dialect = con['storageDriver'];
let dataSource;
if (dialect === 'sqlite') {
dataSource = new DataSource({
type: 'sqlite',
database: con['storageFile'],
synchronize: false,
logging: true
});
} else {
const host = con['storageServer']; const host = con['storageServer'];
const port = con['storagePort']; const port = con['storagePort'];
const storageName = con['storageName']; const storageName = con['storageName'];
const username = con['storageUsername']; const username = con['storageUsername'];
const password = con['storagePassword']; const password = con['storagePassword'];
let dataSource;
if (dialect === 'sqlite') {
dataSource = new DataSource({
type: 'sqlite',
database: storageName
});
} else {
dataSource = new DataSource({ dataSource = new DataSource({
type: dialect as any, type: dialect as any,
host: host, host: host,

View file

@ -1,7 +0,0 @@
REM SET SCHEDULE "* 8 * * * *"
user = user@domain.com
pass= "*************"
o =get "https://oooooooooo"
caption = REWRITE "Crie um post sobre hotmart e seus produtos, no estilo dica do dia incluíndo 10 hashtags, estilo instagram o texto! Importante, retorne só a saída de texto pronta"
image = GET IMAGE caption
POST username, password, image, caption

View file

@ -0,0 +1,20 @@
REM SET SCHEDULE "* 8 * * * *"
user = "user@domain.com"
pass = "*************"
o = get "https://oooooooooo"
# Criar a legenda para o post
caption = REWRITE "Crie um post sobre Hotmart e seus produtos, no estilo dica do dia, incluindo 10 hashtags, estilo Instagram o texto! Importante, retorne só a saída de texto pronta"
# Obter uma imagem relacionada ao conteúdo
image = GET IMAGE caption
# Postar no Instagram
POST TO INSTAGRAM username, password, image, caption
# Postar no Facebook
POST TO FACEBOOK username, password, image, caption
# Postar no Twitter
TWEET username, password, image, caption

View file

@ -0,0 +1,10 @@
data = FIND "products.csv"
BEGIN SYSTEM PROMPT
Engage users effectively as if you're a sales assistant in the virtual store.
Begin by welcoming them warmly and encouraging them to explore our range of products.
Provide clear instructions on how to inquire about specific items or browse
categories. Ensure the tone is friendly, helpful, and inviting to encourage
interaction. Use prompts to guide users through the purchasing process and offer
assistance whenever needed. Offer them this products: ${ TOJSON (data) }
END SYSTEM PROMPT

View file

@ -0,0 +1,4 @@
name,value
Answer Mode,sql
llm File,northwind.db
llm Driver,sqlite
1 name value
2 Answer Mode sql
3 llm File northwind.db
4 llm Driver sqlite