From 5b69a12d744367033cf52b561ca25ae5ca6256b7 Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Sun, 24 Nov 2024 12:43:58 -0300 Subject: [PATCH] fix(llm.gblib): Talk to data local db use fix. --- packages/kb.gbapp/services/KBService.ts | 9 ++-- packages/llm.gblib/services/ChatServices.ts | 44 ++++++++++++------- .../talk-to-data.gbot/config.csv | 3 +- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/packages/kb.gbapp/services/KBService.ts b/packages/kb.gbapp/services/KBService.ts index 8787eb03..fe5be172 100644 --- a/packages/kb.gbapp/services/KBService.ts +++ b/packages/kb.gbapp/services/KBService.ts @@ -656,9 +656,7 @@ export class KBService implements IGBKBService { // Checks for text after the image markdown, after the element 4, there are text blocks. - const removeMarkdownImages = (text: string) => { - // Remove both inline images ![alt](url) and reference images ![alt][ref] return text.replace(/!\[[^\]]*\](?:\([^)]*\)|\[[^\]]*\])/g, '').trim(); } @@ -1046,7 +1044,8 @@ export class KBService implements IGBKBService { const websiteIgnoreUrls = min.core.getParam<[]>(min.instance, 'Website Ignore URLs', null); GBLogEx.info(min, `Website: ${website}, Max Depth: ${maxDepth}, Ignore URLs: ${websiteIgnoreUrls}`); - + let shouldSave = false; + if (website) { // Removes last slash if any. @@ -1128,6 +1127,7 @@ export class KBService implements IGBKBService { await CollectionUtil.asyncForEach(files, async file => { let content = null; + shouldSave = true; try { const document = await this.loadAndSplitFile(file); @@ -1144,6 +1144,7 @@ export class KBService implements IGBKBService { files = await walkPromise(urlJoin(localPath, 'docs')); if (files[0]) { + shouldSave = true; GBLogEx.info(min, `Add embeddings from .gbkb: ${files.length}}...`); await CollectionUtil.asyncForEach(files, async file => { let content = null; @@ -1154,7 +1155,7 @@ export class KBService implements IGBKBService { await min['vectorStore'].addDocuments(flattenedDocuments); }); } - if (min['vectorStore']) { + if (shouldSave && min['vectorStore']) { await min['vectorStore'].save(min['vectorStorePath']); } } diff --git a/packages/llm.gblib/services/ChatServices.ts b/packages/llm.gblib/services/ChatServices.ts index 809b36c3..aad20055 100644 --- a/packages/llm.gblib/services/ChatServices.ts +++ b/packages/llm.gblib/services/ChatServices.ts @@ -538,22 +538,36 @@ export class ChatServices { 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, - port: port, - database: storageName, - username: username, - password: password, - synchronize: false, - logging: true - }); + + if (dialect === 'sqlite') { + const storageFile = con['storageFile']; + dataSource = new DataSource({ + type: 'sqlite', + database: 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, + port: port, + database: storageName, + username: username, + password: password, + synchronize: false, + logging: true + }); + } } const db = await SqlDatabase.fromDataSourceParams({ diff --git a/templates/talk-to-data.gbai/talk-to-data.gbot/config.csv b/templates/talk-to-data.gbai/talk-to-data.gbot/config.csv index 49fd29eb..14b550bd 100644 --- a/templates/talk-to-data.gbai/talk-to-data.gbot/config.csv +++ b/templates/talk-to-data.gbai/talk-to-data.gbot/config.csv @@ -1,7 +1,6 @@ name,value Admin, 5521999998888 -Answer Mode,sql -Answer Source,cache +Answer Mode,chart llm File,northwind.db llm Driver,sqlite Theme Color,red \ No newline at end of file