Unable to access the table names, which are in synonyms, views by using langchain SQLDatabasechain and oracle database #15701
vijayinfy0306
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm new to this langchain. Here, what I'm trying to build is a text-to-sql application. But I am unable to access the table names, which are in synonyms, views by using langchain SQLDatabasechain. Could anyone help me out with this? Here is the code. Please have a look and tell me where I made the mistake.
`import os
import sys
import cx_Oracle
from langchain.utilities import SQLDatabase
from langchain.llms import OpenAI
from langchain_experimental.sql import SQLDatabaseChain
from sqlalchemy import create_engine
import constants #Importing OpenAPIKey from constants file
os.environ["OPENAI_API_KEY"] = constants.APIKEY
Declaring Database Details
IP="IP Address"
PORT="POSRT"
servicename="ORACLE_SERVICENAME"
username="USERNAME"
password="PASSWORD"
Developing the oracle Connection
oracle_connection_string_fmt = (f'oracle+cx_oracle://{username}:{password}@' + cx_Oracle.makedsn(f'{IP}', f'{PORT}', service_name=f'{servicename}'))
url = oracle_connection_string_fmt.format(username=username, password=password, hostname=IP, port=PORT, service_name=servicename,)
engine=create_engine(url, echo=True)
db = SQLDatabase(engine)
llm = OpenAI(temperature=0.01, verbose=True)
db_chain = SQLDatabaseChain.from_llm(llm, db, verbose=True)
while True:
query = input("Query Please: ") # query = "Is employee code 7365 exist or not?"
if query in ('q', 'quit', 'exit'):
break
sys.exit()
value = db_chain.run(query)
print(value)`
Beta Was this translation helpful? Give feedback.
All reactions