Find answers from the community

Updated 3 months ago

Hi guys,

Hi guys,

I am using the text-to-sql functionnality engine NLSQLTableQueryEngine (from llama-index 0.8.62) to query a database from natural language questions.
It works great when I plug it to openai, but the I have installed a local Mixtral-8x7b with an API supposedly compatible with openai API.

I use the exact same code for both cases I just change the base_url in the llm = OpenAI(...) initialization. All functions work except the NLSQLTableQueryEngine.query that seems to fail to execute the SQL statement weirdly:

'''Error: Statement "SELECT sum(Quantity) as TotalQuantity \nFROM xxxxxxxx WHERE Type LIKE 'deal%'" is invalid SQL.'''

The SQL is valid so there must be some missing context somewhere that make it fail.

any hint ? do you think it should work in the first place ?
L
g
31 comments
if you set verbose=True in the constructor, do you see a log like

> Predicted SQL query: ....

in the terminal?
I am struggling to add the verbose mode as NLSQLTableQueryEngine does not accept it
this is my code :
llm = OpenAI(temperature=self.config.temperature, api_base=self.config.mixtral2_api_url)
service_context = ServiceContext.from_defaults(llm=llm)
query_engine = NLSQLTableQueryEngine(
sql_database=self.get_sql_database(),
tables=list(included_tables.views.keys()),
synthesize_response=True,
text_to_sql_prompt=PromptTemplate(prompt_text, template_var_mappings={}),
service_context=service_context)
response = query_engine.query(question )
where can I put verbose=True you think?
query_engine = NLSQLTableQueryEngine(..., verbose=True)
File "C:\Users\guillaume\Documents\GitHub\starboard\src\starboard.py", line 402, in get_database_answer
query_engine = NLSQLTableQueryEngine(
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guillaume.conda\envs\starboard\Lib\site-packages\llama_index\indices\struct_store\sql_query.py", line 377, in init
super().init(
File "C:\Users\guillaume.conda\envs\starboard\Lib\site-packages\llama_index\indices\struct_store\sql_query.py", line 270, in init
super().init(self._service_context.callback_manager, **kwargs)
TypeError: BaseQueryEngine.init() got an unexpected keyword argument 'verbose'
Seems like the constructor does not accept this parameter
what version of llama-index do you have? I'm looking at the source code right now
ah, yea that version does not appear to have that option
Yea -- I was looking at the latest above. Im assuming you have 0.8.62 due to openai updating after that?

Looking at the source code for 0.8.62 there is another option, but it is much more verbose
Plain Text
import logging
import sys

logging.basicConfig(
    stream=sys.stdout, level=logging.DEBUG
)
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
yes I dont want to update the openai package yet
we can use debug logging on the logger to see the same log
So this will show the exact string that its running, so we can confirm what it looks like πŸ‘
interesting. it actually succeeds
but it does another iteration and answer that it failed
hmmm, yea I see it still has an issue running this query

Plain Text
SELECT SUM(Quantity) as TotalDeals
FROM Starboard\_PhysicalMovementsBoughtStockSold
WHERE Type LIKE 'deal%'


Is that valid SQL? Does that work if you run it yourself?
except for the \_ in the table name
there is a backslash that shouldnt be there
might be the issue
if that is the case it comes from my llm not outputting valid sql indeed
I will investigate that. thank you for your debug trick ! very useful!
Glad I could help a bit!
well I dont know if the backslah is only added in the log or if it is in the query actually
but I will get rid of it!
In the future, I would like to add a hook to pre-process the SQL before running it, just haven't got around to it πŸ˜…
it is already great like that. thanks for this great package !
Add a reply
Sign up and join the conversation on Discord