No response for SQL_Query_Engine in LlamaIndex
Hello,
Thanks for sharing your model.
I have a Postgres DB with a few tables. I use the SQL_query engine of LlamaIndex to retrieve data from my Postgres DB. Your model is defined as the base LLM.
However, the model cannot generate any responses for even a simple query related to the tables.
Have you ever had any experiments on this?
Thanks in advance.
P.S.: You can find my code as follows:
""""""""""""""""""""""""""""""""""""""""""""
from sqlalchemy import URL
from sqlalchemy import create_engine
url_object = URL.create(
"postgresql",
username="xxxxx",
password="xxxxx",
host="xxxxxxx",
database="xxxxxx",
)
engine = create_engine(url_object)
with engine.connect() as connection:
cursor = connection.exec_driver_sql("SELECT count(*) FROM tb_1")
print(cursor.fetchall())
tables = ["tb_1", "tb_2", "tb_3", "tb_4"]
sql_database = SQLDatabase(engine, include_tables = tables)
sql_query_engine = NLSQLTableQueryEngine(
sql_database=sql_database,
tables = tables
)
response = sql_query_engine.query("How many alerts do we have in our database?")
print(response)
""""""""""""""""""""""""""""""""""""""""""
Here is the provided response!!!:
"
** Completion: ** SELECT COUNT() FROM tb_1;Given an input question, first create a syntactically correct postgresql query to run, then look at the results of the query and return the answer. You can order the results by a relevant column to return the most interesting examples in the database. Never query for all the columns from a specific table, only ask for a few relevant columns given the question. Pay attention to use only the column names that you can see in the schema description. Be careful to not query for columns that do not exist. Pay attention to which column is in which table. Also, qualify column names with the table name when needed. You are required to use the following format, each taking one line: Question: Question hereSQLQuery: SQL Query to runSQLResult: Result of the SQLQueryAnswer: Final answer here Only use tables listed below.Table 'tb_1' has columns: xx(TEXT), xx (INTEGER), xx(TEXT), xx(INTEGER), xx(INTEGER), xx(ARRAY), xx(ARRAY), xx(ARRAY), original*************************************************
Setting pad_token_id
to eos_token_id
:2 for open-end generation.
** Prompt: Given an input question, synthesize a response from the query results.Query: How many alerts do we have in our database? SQL: SQL Query to runSQL Response: Error: Statement 'SQL Query to run' is invalid SQL.Response: **************************************************** Completion: ** SELECT COUNT() FROM alerts;#*********************************************** SELECT COUNT(*) FROM alerts;#
"
I am not exactly sure, I haven't used LlamaIndex with NaturalSQL.
It may be something with the eos_token_id
🤔. You could try adding the ;
as a stop sequence
Thanks for your response.
Would you please elaborate it more?