An error occurred: SQLDatabaseChain
is not fully defined; you should define BaseCache
, then call SQLDatabaseChain.model_rebuild()
.
#29052
Replies: 2 comments 1 reply
-
from langchain_google_genai import ChatGoogleGenerativeAI llm = GoogleGenerativeAI(model="models/gemini-1.0-pro", google_api_key=gooapi_key, temperature=0.2) db_chain = SQLDatabaseChain.from_llm(llm=llm, db=db, verbose=True) I get PydanticUserError: For further information visit https://errors.pydantic.dev/2.10/u/class-not-fully-defined |
Beta Was this translation helpful? Give feedback.
-
install pydantic@2.9.2,already resolve |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
SO I am doing a basic python script to connect to an existing oracle database and nothing I do will stop this error from comming up.
I think it may be some version issue with particular libraries. Python 3.12.3
Here is the code
#from langchain_community.llms import OpenAI, Cohere
#from langchain import Cohere
from langchain_community.llms import Cohere
from langchain_community.utilities import SQLDatabase
from langchain_experimental.sql import SQLDatabaseChain
from typing import Dict, Any
from cache.base_cache import BaseCache
from langchain_community.cache import InMemoryCache
from pydantic import BaseModel
Define the BaseCache class
class BaseCache(BaseModel):
cache: Dict[str, Any]
Initialize the cache
cache = BaseCache(cache={})
import cx_Oracle
import os
import cohere
from langchain.chains import load_chain
#from cache.in_memory_cache import InMemoryCache
from langchain_community.cache import InMemoryCache
import os
#cache = BaseCache()
COHERE_API_KEY='WQkUQh3NrSYVJBTEWNjRHmBX3912HUVuuePk4H4N'
os.environ["COHERE_API_KEY"] = COHERE_API_KEY
lib_dir = os.path.join(os.environ.get("HOME"), "Development", "instantclient_23_6")
cx_Oracle.init_oracle_client(lib_dir=lib_dir)
hostname='192.168.160.83'
port='1521'
service_name='xxxxxx'
username='xxxxxxxx'
password='xxxxxx'
cx_Oracle.init_oracle_client(lib_dir=lib_dir)
oracle_connection_string_fmt = (
'oracle+cx_oracle://{username}:{password}@' +
cx_Oracle.makedsn('{hostname}', '{port}', service_name='{service_name}')
)
url = oracle_connection_string_fmt.format(
username=username, password=password,
hostname=hostname, port=port,
service_name=service_name,
)
from sqlalchemy import create_engine
engine=create_engine(url, echo=True)
db = SQLDatabase(engine)
#llm = Cohere(temperature=1, verbose=True)
#db_chain = SQLDatabaseChain.from_llm(llm, db,cache=cache, verbose=True)
#db_chain.model_rebuild()
#db_chain.run("Is Casey Brown in the database?")
try:
llm = Cohere(temperature=1, verbose=True)
except Exception as e:
print(f"An error occurred: {str(e)}")
Any Ideas
Beta Was this translation helpful? Give feedback.
All reactions