fix(KBService): standardize formatting and improve code readability
All checks were successful
GBCI / build (push) Successful in 1m13s
All checks were successful
GBCI / build (push) Successful in 1m13s
This commit is contained in:
parent
e2382ccddc
commit
2b2ab3a42e
3 changed files with 30 additions and 19 deletions
|
|
@ -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];
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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)}`);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
Loading…
Add table
Reference in a new issue