Skip to content

Commit

Permalink
fix(llm.gblib): Talk to data local db use fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed Nov 28, 2024
1 parent c62db78 commit 5e8e3cb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
3 changes: 2 additions & 1 deletion packages/core.gbapp/services/GBDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 9 additions & 6 deletions packages/llm.gblib/services/ChatServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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,
Expand All @@ -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}
------------
Expand All @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion templates/talk-to-data.gbai/talk-to-data.gbot/config.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5e8e3cb

Please sign in to comment.