I was working with a sqlite DB that I created for a large dataset (~150k rows).
Code snippets:
db = SQLDatabase.from_uri("sqlite:///MLdata.sqlite")
SQLITE_PROMPT_TEXT = '''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 {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.
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.
Use the following format:
Question: Question here
SQLQuery: SQL Query to run
SQLResult: Result of the SQLQuery
Answer: Final answer here
Only use the following tables:
{table_info}
Question: {input}'''
SQLITE_PROMPT = PromptTemplate(input_variables=['input', 'table_info', 'top_k'], template=SQLITE_PROMPT_TEXT)
sql_chain = SQLDatabaseChain(llm=local_llm, database=db, prompt=SQLITE_PROMPT, return_direct=False, return_intermediate_steps=False, verbose=False)
res=sql_chain("How many rows is in this db?")
Response: 'There are 142321 rows in the input_table of this db.'
Second query
res=sql_chain("Count rows with 'Abdominal pain', VAX_TYPE='COVID19', SEX= 'F' and HOSPITAL= 'Y' is in the input_table of this db")
Response: 'There are 115 rows in the input_table where Abdominal pain is present, VAX_TYPE is COVID19, Sex is Female, and Hospital is Yes.'
Third query I was trying to find the patient ID only instead of the count. But I am not able to get the patient ID.
res=sql_chain("What is the VAERS_ID with 'Abdominal pain', VAX_TYPE='COVID19', SEX= 'F' and HOSPITAL= 'Y' in this db. ")
Seems like the counting is working fine but nothing more. Can anyone help me in displaying table like output from sqlDbchain via langchain and llama2?