Find answers from the community

Updated 2 years ago

Sql database

Here is my code and the error I am getting

sql_database = SQLDatabase.from_uri(db_uri) table_node_mapping = SQLTableNodeMapping(sql_database) all_table_names = [ "responses", "demographic", "respondents"] table_schema_objs = [] for table_name in all_table_names: table_schema_objs.append(SQLTableSchema(table_name=table_name)) obj_index = ObjectIndex.from_objects( table_schema_objs, table_node_mapping, VectorStoreIndex, )

python main.py Traceback (most recent call last): File "C:\Users\hp\Desktop\openai\main.py", line 64, in <module> obj_index = ObjectIndex.from_objects( File "C:\Users\hp\Desktop\openai\jmf-env\lib\site-packages\llama_index\objects\base.py", line 50, in from_objects nodes = object_mapping.to_nodes(objects) File "C:\Users\hp\Desktop\openai\jmf-env\lib\site-packages\llama_index\objects\base_node_mapping.py", line 55, in to_nodes return [self.to_node(obj) for obj in objs] File "C:\Users\hp\Desktop\openai\jmf-env\lib\site-packages\llama_index\objects\base_node_mapping.py", line 55, in <listcomp> return [self.to_node(obj) for obj in objs] File "C:\Users\hp\Desktop\openai\jmf-env\lib\site-packages\llama_index\objects\table_node_mapping.py", line 46, in to_node f"{self._sql_database.get_single_table_info(obj.table_name)}\n" AttributeError: 'SQLDatabase' object has no attribute 'get_single_table_info'

Can someone help me how to resolve this error? I have tried to check my code everything seems to work perfectly fine
L
B
7 comments
Where did you import SQLDatabase from?
The database is a PostgreSQL instance running in Digital Ocean, I am able to connect to it and get access to all the tables metadata and schema. But when i try to add some more table that need to be included in the prompt I could not use the basic implementation. That's why I want to do it using SQLContextContainerBuilder. After running the that's the error I am getting.
Current packages

langchain==0.0.214 langchainplus-sdk==0.0.17 llama-hub==0.0.4 llama-index==0.6.32 SQLAlchemy==2.0.17
Right, but the error is saying a function doesn't exist on the SQLDatabase class, but it does in the source code.

Did you import it from llama index or langchain?
Ohh yes, I have run a diagnosis of my imports, I came to realize that there was another SQLDatabase class from langchain that was overriding the first on from llamindex. Thanks so very much @Logan M for the assistance.
Add a reply
Sign up and join the conversation on Discord