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.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.title = botId;
instance.activationCode = instance.botId.substring(0, 15); instance.activationCode = instance.botId.substring(0, 15);
instance.state = 'active'; instance.state = 'active';
@ -371,9 +371,20 @@ export class GBDeployer implements IGBDeployer {
vectorStore = await HNSWLib.load(min['vectorStorePath'], embedding); vectorStore = await HNSWLib.load(min['vectorStorePath'], embedding);
} catch (e) { } catch (e) {
GBLogEx.info(min, `Creating new store...`); GBLogEx.info(min, `Creating new store...`);
vectorStore = new HNSWLib(embedding, { vectorStore = await HNSWLib.fromTexts(
space: 'cosine' ['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; return vectorStore;
} }
@ -483,7 +494,7 @@ export class GBDeployer implements IGBDeployer {
} else { } else {
return []; return [];
} }
1
await asyncPromise.eachSeries(rows, async (line: any) => { await asyncPromise.eachSeries(rows, async (line: any) => {
if (line && line.length > 0) { if (line && line.length > 0) {
const key = line[1]; const key = line[1];
@ -523,7 +534,7 @@ export class GBDeployer implements IGBDeployer {
secretKey: process.env.DRIVE_SECRET, 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))) { if (!(await GBUtil.exists(localPath))) {
await fs.mkdir(localPath, { recursive: true }); await fs.mkdir(localPath, { recursive: true });
@ -547,13 +558,13 @@ export class GBDeployer implements IGBDeployer {
} }
} }
// Only download text files if onlyTextFiles flag is set // Only download text files if onlyTextFiles flag is set
if (onlyTextFiles) { if (onlyTextFiles) {
// Check if file is NOT one of the allowed text file types // 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)) { if (!obj.name.match(/\.(txt|json|csv|xlsx?|xlsm|xlsb|xml|html?|md|docx?|pdf|pptx?)$/i)) {
download = false; download = false;
} }
} }
if (download) { if (download) {
@ -684,7 +695,7 @@ export class GBDeployer implements IGBDeployer {
const filePath = path.join(GBConfigService.get('STORAGE_LIBRARY'), gbai, packageName); const filePath = path.join(GBConfigService.get('STORAGE_LIBRARY'), gbai, packageName);
if (packageType === '.gbdrive' || packageType === '.gbdata') { if (packageType === '.gbdrive' || packageType === '.gbdata') {
await GBUtil.copyIfNewerRecursive(filePath, packageWorkFolder, true); await GBUtil.copyIfNewerRecursive(filePath, packageWorkFolder, true);
}else { } else {
await GBUtil.copyIfNewerRecursive(filePath, packageWorkFolder, false); await GBUtil.copyIfNewerRecursive(filePath, packageWorkFolder, false);
} }
} else { } else {
@ -692,8 +703,7 @@ export class GBDeployer implements IGBDeployer {
if (packageType === '.gbdrive' || packageType === '.gbdata') { if (packageType === '.gbdrive' || packageType === '.gbdata') {
await this.downloadFolder(min, path.join('work', `${gbai}`), packageName, undefined, undefined, true); await this.downloadFolder(min, path.join('work', `${gbai}`), packageName, undefined, undefined, true);
} }
else else {
{
await this.downloadFolder(min, path.join('work', `${gbai}`), packageName); await this.downloadFolder(min, path.join('work', `${gbai}`), packageName);
} }
} }
@ -733,8 +743,8 @@ export class GBDeployer implements IGBDeployer {
switch (packageType) { switch (packageType) {
case '.gbdrive': case '.gbdrive':
break; break;
case '.gbdata': case '.gbdata':
break; break;
case '.gbot': case '.gbot':
// Extracts configuration information from .gbot files. // 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); let website = min.core.getParam<string>(min.instance, 'Website', null);
const maxDepth = min.core.getParam<number>(min.instance, 'Website Depth', 1); const maxDepth = min.core.getParam<number>(min.instance, 'Website Depth', 1);
const MAX_DOCUMENTS = 15; 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); 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}`); 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 { try {
const document = await this.loadAndSplitFile(file); const document = await this.loadAndSplitFile(file);
const flattenedDocuments = document.reduce((acc, val) => acc.concat(val), []); const flattenedDocuments = document.reduce((acc, val) => acc.concat(val), []);
// await min['vectorStore'].addDocuments(flattenedDocuments); await min['vectorStore'].addDocuments(flattenedDocuments);
} catch (error) { } catch (error) {
GBLogEx.info(min, `Ignore processing of ${file}. ${GBUtil.toYAML(error)}`); GBLogEx.info(min, `Ignore processing of ${file}. ${GBUtil.toYAML(error)}`);
} }

View file

@ -1,5 +1,6 @@
name,value name,value
Website,https://pragmatismo.com.br/ Website,https://pragmatismo.com.br/
website Max Documents, 2
Answer Mode,document Answer Mode,document
Theme Color,purple Theme Color,purple
LLM Provider,openai 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