Find answers from the community

Updated 3 months ago

Text 2 SQL

https://docs.llamaindex.ai/en/stable/examples/index_structs/struct_indices/SQLIndexDemo.html
I read the text 2 sql demo but haven't found where openai is used here. Is there a complete code rather than step by step?
W
t
L
5 comments
https://docs.llamaindex.ai/en/stable/examples/index_structs/struct_indices/SQLIndexDemo.html#part-1-text-to-sql-query-engine

NLSQLTableQueryEngine uses llm to convert queries into sql queries. It can be either openai or any opensource llm.
well. So when a sqldatabase instance is initialized there should be an engine and that's where the open ai input?
https://docs.llamaindex.ai/en/stable/examples/index_structs/struct_indices/SQLIndexDemo.html#define-sql-database

Plain Text
from llama_index import SQLDatabase, ServiceContext
from llama_index.llms import OpenAI
llm = OpenAI(temperature=0.1, model="gpt-3.5-turbo")
service_context = ServiceContext.from_defaults(llm=llm)
sql_database = SQLDatabase(~~engine~~ service_context , include_tables=["city_stats"])

Just need to replace engine with service_context, right?
@tian7.eth just add the service context as a kwarg when constructing the query engine
Thanks. I wonder why it doesn't add the service context arg when declaring the query engine. And where I can more examples using query engine. I want to know which parameters it supports
Add a reply
Sign up and join the conversation on Discord