new(basic.gblib): New batch features.

This commit is contained in:
Rodrigo Rodriguez 2024-08-13 21:00:08 -03:00
parent 7b9d7446da
commit b87f19e9d3

View file

@ -516,14 +516,12 @@ export class ChatServices {
/** /**
* Create a new RunnableSequence where we pipe the output from `db.getTableInfo()` * Create a new RunnableSequence where we pipe the output from `db.getTableInfo()`
* and the users question, into the prompt template, and then into the llm.
* We're also applying a stop condition to the llm, so that it stops when it
* sees the `\nSQLResult:` token.
*/ */
const sqlQueryChain = RunnableSequence.from([ const sqlQueryChain = RunnableSequence.from([
{ {
schema: async () => db.getTableInfo(), schema: async () => db.getTableInfo(),
question: (input: { question: string }) => input.question question: (input: { question: string }) => input.question ,
top_k: ()=>10
}, },
prompt, prompt,
model, model,
@ -537,7 +535,7 @@ export class ChatServices {
const finalResponsePrompt = SQL_SQLITE_PROMPT const finalResponsePrompt = SQL_SQLITE_PROMPT
PromptTemplate.fromTemplate(`Based on the table schema below, question, SQL query, and SQL response, write a natural language response: PromptTemplate.fromTemplate(`Based on the table schema below, question, SQL query, and SQL response, write a natural language response:
You are a SQLite expert. Given an input question, first create a syntactically correct SQLite query to run, then look at the results of the query and return the answer to the input question. You are a SQLite expert. Given an input question, first create a syntactically correct SQLite query to run, then look at the results of the query and return the answer to the input question.
Unless the user specifies in the question a specific number of examples to obtain, query for at most results using the LIMIT clause as per SQLite. You can order the results to return the most informative data in the database. Unless the user specifies in the question a specific number of examples to obtain, query for at most {top_k} results using the LIMIT clause as per SQLite. You can order the results to return the most informative data in the database.
Never query for all columns from a table. You must query only the columns that are needed to answer the question. Wrap each column name in double quotes (") to denote them as delimited identifiers. Never query for all columns from a table. You must query only the columns that are needed to answer the question. Wrap each column name in double quotes (") to denote them as delimited identifiers.
Pay attention to use only the column names you can see in the tables below. Be careful to not query for columns that do not exist. Also, pay attention to which column is in which table. Pay attention to use only the column names you can see in the tables below. Be careful to not query for columns that do not exist. Also, pay attention to which column is in which table.
@ -563,13 +561,14 @@ Pay attention to use only the column names you can see in the tables below. Be c
const finalChain = RunnableSequence.from([ const finalChain = RunnableSequence.from([
{ {
question: input => input.question, question: input => input.question,
query: sqlQueryChain query: sqlQueryChain,
}, },
{ {
schema: async () => db.getTableInfo(), schema: async () => db.getTableInfo(),
question: input => input.question, question: input => input.question,
query: input => input.query, query: input => input.query,
response: input => db.run(input.query) response: input => db.run(input.query),
top_k: ()=>10
}, },
{ {
result: finalResponsePrompt.pipe(model).pipe(new StringOutputParser()), result: finalResponsePrompt.pipe(model).pipe(new StringOutputParser()),