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 }) {
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,6 +221,72 @@ export class GBVMService extends GBService {
}
}
public static async loadConnections(min) {
// Loads storage custom connections.
const path = DialogKeywords.getGBAIPath(min.botId, null);
const filePath = Path.join('work', path, 'connections.json');
let connections = [];
if (Fs.existsSync(filePath)) {
connections = JSON.parse(Fs.readFileSync(filePath, 'utf8'));
}
connections.forEach(async con => {
const connectionName = con['name'];
const dialect = con['storageDriver'];
const host = con['storageServer'];
const port = con['storagePort'];
const storageName = con['storageName'];
const username = con['storageUsername'];
const password = con['storagePassword'];
const logging: boolean | Function =
GBConfigService.get('STORAGE_LOGGING') === 'true'
? (str: string): void => {
GBLogEx.info(min, str);
}
: false;
const encrypt: boolean = GBConfigService.get('STORAGE_ENCRYPT') === 'true';
const acquire = parseInt(GBConfigService.get('STORAGE_ACQUIRE_TIMEOUT'));
const sequelizeOptions = {
define: {
charset: 'utf8',
collate: 'utf8_general_ci',
freezeTableName: true,
timestamps: false
},
host: host,
port: port,
logging: logging as boolean,
dialect: dialect,
quoteIdentifiers: false, // set case-insensitive
dialectOptions: {
options: {
trustServerCertificate: true,
encrypt: encrypt,
requestTimeout: 120 * 1000
}
},
pool: {
max: 5,
min: 0,
idle: 10000,
evict: 10000,
acquire: acquire
}
};
if (!min[connectionName]) {
GBLogEx.info(min, `Loading custom connection ${connectionName}...`);
min[connectionName] = new Sequelize(storageName, username, password, sequelizeOptions);
min[connectionName]['gbconnection'] = con;
}
});
}
private syncStorageFromTABLE(folder: string, filename: string, min: GBMinInstance, mainName: string) {
const tablesFile = urlJoin(folder, `${filename}.tables.json`);
let sync = false;
@ -282,68 +348,6 @@ export class GBVMService extends GBService {
const associations = [];
// Loads storage custom connections.
const path = DialogKeywords.getGBAIPath(min.botId, null);
const filePath = Path.join('work', path, 'connections.json');
let connections = [];
if (Fs.existsSync(filePath)) {
connections = JSON.parse(Fs.readFileSync(filePath, 'utf8'));
}
connections.forEach(async con => {
const connectionName = con['name'];
const dialect = con['storageDriver'];
const host = con['storageServer'];
const port = con['storagePort'];
const storageName = con['storageName'];
const username = con['storageUsername'];
const password = con['storagePassword'];
const logging: boolean | Function =
GBConfigService.get('STORAGE_LOGGING') === 'true'
? (str: string): void => {
GBLogEx.info(min, str);
}
: false;
const encrypt: boolean = GBConfigService.get('STORAGE_ENCRYPT') === 'true';
const acquire = parseInt(GBConfigService.get('STORAGE_ACQUIRE_TIMEOUT'));
const sequelizeOptions = {
define: {
charset: 'utf8',
collate: 'utf8_general_ci',
freezeTableName: true,
timestamps: false
},
host: host,
port: port,
logging: logging as boolean,
dialect: dialect,
quoteIdentifiers: false, // set case-insensitive
dialectOptions: {
options: {
trustServerCertificate: true,
encrypt: encrypt,
requestTimeout: 120 * 1000
}
},
pool: {
max: 5,
min: 0,
idle: 10000,
evict: 10000,
acquire: acquire
}
};
if (!min[connectionName]) {
GBLogEx.info(min, `Loading custom connection ${connectionName}...`);
min[connectionName] = new Sequelize(storageName, username, password, sequelizeOptions);
min[connectionName]['gbconnection'] = con;
}
});
const shouldSync = min.core.getParam<boolean>(min.instance, 'Synchronize Database', false);
tableDef.forEach(async t => {
@ -1144,7 +1148,6 @@ export class GBVMService extends GBService {
});
const s = new VMScript(code, { filename: scriptPath });
result = vm1.run(s);
});
})();
} else {

View file

@ -724,7 +724,7 @@ ENDPOINT_UPDATE=true
* @param name Name of param to get from instance.
* @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 params;
name = name.trim();
@ -774,6 +774,10 @@ ENDPOINT_UPDATE=true
value = null;
}
if (!value && platform){
value = process.env[name.replace(/ /g, "_").toUpperCase()];
}
if (value && typeof defaultValue === 'boolean') {
return new Boolean(value ? value.toString().toLowerCase() === 'true' : defaultValue).valueOf();
}

View file

@ -447,7 +447,7 @@ export class GBDeployer implements IGBDeployer {
rows.shift();
}
} 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
rows = worksheet.getSheetValues();
@ -636,12 +636,23 @@ export class GBDeployer implements IGBDeployer {
const connectionName = t.replace(strFind, '');
let con = {};
con['name'] = connectionName;
con['storageServer'] = min.core.getParam<string>(min.instance, `${connectionName} Server`, 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['storagePassword'] = min.core.getParam<string>(min.instance, `${connectionName} Password`, null);
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['storageUsername'] = min.core.getParam<string>(min.instance, `${connectionName} Username`, null);
con['storagePort'] = min.core.getParam<string>(min.instance, `${connectionName} Port`, null);
con['storagePassword'] = min.core.getParam<string>(min.instance, `${connectionName} Password`, 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);
});

View file

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

View file

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

View file

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