fix(KBService): standardize formatting and improve code readability
All checks were successful
GBCI / build (push) Successful in 1m13s

This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2025-05-22 20:32:30 -03:00
parent e2382ccddc
commit 2b2ab3a42e
3 changed files with 30 additions and 19 deletions

View file

@ -241,7 +241,7 @@ export class GBDeployer implements IGBDeployer {
instance.marketplacePassword = await service.createApplicationSecret(accessToken, (application as any).id);
}
instance.adminPass =await GBUtil.hashPassword( GBAdminService.getRndPassword());
instance.adminPass = await GBUtil.hashPassword(GBAdminService.getRndPassword());
instance.title = botId;
instance.activationCode = instance.botId.substring(0, 15);
instance.state = 'active';
@ -277,17 +277,17 @@ export class GBDeployer implements IGBDeployer {
return await GuaribasInstance.findOne({
where: where
}) !== null;
}
else {
const service = await AzureDeployerService.createInstance(this);
return await service.botExists(botId);
}
}
/**
* Performs all tasks of deploying a new bot on the cloud.
*/
@ -371,9 +371,20 @@ export class GBDeployer implements IGBDeployer {
vectorStore = await HNSWLib.load(min['vectorStorePath'], embedding);
} catch (e) {
GBLogEx.info(min, `Creating new store...`);
vectorStore = new HNSWLib(embedding, {
space: 'cosine'
});
vectorStore = await HNSWLib.fromTexts(
['This is General Bots.'], // Initial texts (empty)
{}, // Optional metadata
embedding,
{
'space': 'cosine',
} as any
);
const dir = path.dirname(min['vectorStorePath']);
if (!(await GBUtil.exists(dir))) {
fs.mkdir(dir, { recursive: true });
}
await vectorStore.save(min['vectorStorePath']);
}
return vectorStore;
}
@ -483,7 +494,7 @@ export class GBDeployer implements IGBDeployer {
} else {
return [];
}
1
await asyncPromise.eachSeries(rows, async (line: any) => {
if (line && line.length > 0) {
const key = line[1];
@ -523,7 +534,7 @@ export class GBDeployer implements IGBDeployer {
secretKey: process.env.DRIVE_SECRET,
});
const bucketName = (process.env.DRIVE_ORG_PREFIX + min.botId + '.gbai').toLowerCase();
const bucketName = (process.env.DRIVE_ORG_PREFIX + min.botId + '.gbai').toLowerCase();
if (!(await GBUtil.exists(localPath))) {
await fs.mkdir(localPath, { recursive: true });
@ -547,13 +558,13 @@ export class GBDeployer implements IGBDeployer {
}
}
// Only download text files if onlyTextFiles flag is set
if (onlyTextFiles) {
// Only download text files if onlyTextFiles flag is set
if (onlyTextFiles) {
// Check if file is NOT one of the allowed text file types
if (!obj.name.match(/\.(txt|json|csv|xlsx?|xlsm|xlsb|xml|html?|md|docx?|pdf|pptx?)$/i)) {
download = false;
}
}
}
if (download) {
@ -684,7 +695,7 @@ export class GBDeployer implements IGBDeployer {
const filePath = path.join(GBConfigService.get('STORAGE_LIBRARY'), gbai, packageName);
if (packageType === '.gbdrive' || packageType === '.gbdata') {
await GBUtil.copyIfNewerRecursive(filePath, packageWorkFolder, true);
}else {
} else {
await GBUtil.copyIfNewerRecursive(filePath, packageWorkFolder, false);
}
} else {
@ -692,8 +703,7 @@ export class GBDeployer implements IGBDeployer {
if (packageType === '.gbdrive' || packageType === '.gbdata') {
await this.downloadFolder(min, path.join('work', `${gbai}`), packageName, undefined, undefined, true);
}
else
{
else {
await this.downloadFolder(min, path.join('work', `${gbai}`), packageName);
}
}
@ -733,8 +743,8 @@ export class GBDeployer implements IGBDeployer {
switch (packageType) {
case '.gbdrive':
break;
case '.gbdata':
break;
case '.gbdata':
break;
case '.gbot':
// Extracts configuration information from .gbot files.

View file

@ -1062,7 +1062,7 @@ export class KBService implements IGBKBService {
let website = min.core.getParam<string>(min.instance, 'Website', null);
const maxDepth = min.core.getParam<number>(min.instance, 'Website Depth', 1);
const MAX_DOCUMENTS = 15;
const maxDocuments = min.core.getParam<number>(min.instance, ' ', MAX_DOCUMENTS);
const maxDocuments = min.core.getParam<number>(min.instance, 'Website Max Documents', MAX_DOCUMENTS);
const websiteIgnoreUrls = min.core.getParam<[]>(min.instance, 'Website Ignore URLs', null);
GBLogEx.info(min, `Website: ${website}, Max Depth: ${maxDepth}, Website Max Documents: ${maxDocuments}, Ignore URLs: ${websiteIgnoreUrls}`);
@ -1222,7 +1222,7 @@ export class KBService implements IGBKBService {
try {
const document = await this.loadAndSplitFile(file);
const flattenedDocuments = document.reduce((acc, val) => acc.concat(val), []);
// await min['vectorStore'].addDocuments(flattenedDocuments);
await min['vectorStore'].addDocuments(flattenedDocuments);
} catch (error) {
GBLogEx.info(min, `Ignore processing of ${file}. ${GBUtil.toYAML(error)}`);
}

View file

@ -1,5 +1,6 @@
name,value
Website,https://pragmatismo.com.br/
website Max Documents, 2
Answer Mode,document
Theme Color,purple
LLM Provider,openai
1 name value
2 Website https://pragmatismo.com.br/
3 website Max Documents 2
4 Answer Mode document
5 Theme Color purple
6 LLM Provider openai