fix(llm.gblib): Talk to data local db use fix.

This commit is contained in:
Rodrigo Rodriguez 2024-11-28 11:13:01 -03:00
parent c62db78e48
commit 5e8e3cbea3
3 changed files with 13 additions and 8 deletions

View file

@ -676,8 +676,9 @@ export class GBDeployer implements IGBDeployer {
let con = {};
con['name'] = connectionName;
con['storageDriver'] = min.core.getParam<string>(min.instance, `${connectionName} Driver`, null);
con['storageTables'] = min.core.getParam<string>(min.instance, `${connectionName} Tables`, 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) {

View file

@ -539,6 +539,8 @@ export class ChatServices {
} else if (LLMMode === 'sql' || LLMMode === 'chart') {
const con = min[`llm`]['gbconnection'];
const dialect = con['storageDriver'];
let tables = con['storageTables'];
tables = tables ? tables.split(';') : null;
const answerSource = await (min.core as any)['getParam'](min.instance,
'Answer Source', 'server');
@ -613,14 +615,14 @@ export class ChatServices {
SQL QUERY:`);
/**
* Create a new RunnableSequence where we pipe the output from `db.getTableInfo()`
* Create a new RunnableSequence.
*/
const sqlQueryChain = RunnableSequence.from([
{
schema: async () => db.getTableInfo(),
schema: async () => db.getTableInfo(tables),
question: (input: { question: string }) => input.question,
top_k: () => 10,
table_info: () => 'any'
table_info: () => 'any',
},
prompt,
model,
@ -633,7 +635,7 @@ export class ChatServices {
*/
const finalResponsePrompt =
PromptTemplate.fromTemplate(`Based on the table schema below, question, SQL query, and SQL response, write a natural language response:
Optimize answers for KPI people. ${systemPrompt}
Optimize answers for KPI people. ${systemPrompt}
------------
SCHEMA: {schema}
------------
@ -659,12 +661,13 @@ export class ChatServices {
query: sqlQueryChain
},
{
schema: async () => db.getTableInfo(),
schema: async () => db.getTableInfo(tables),
question: input => input.question,
query: input => input.query,
response: input => db.run(input.query),
top_k: () => 10,
table_info: () => 'any'
table_info: () => 'any',
table_names_to_use: () => tables
},
{
result: finalResponsePrompt.pipe(model).pipe(

View file

@ -3,4 +3,5 @@ Admin, 5521999998888
Answer Mode,chart
llm File,northwind.db
llm Driver,sqlite
Theme Color,red
llm Tables,Products;Orders;Customers;Categories;Order Details
Theme Color,red

1 name value
3 Answer Mode chart
4 llm File northwind.db
5 llm Driver sqlite
6 Theme Color llm Tables red Products;Orders;Customers;Categories;Order Details
7 Theme Color red