Question:
Fix validation error for SQLDatabaseToolkit

Problem:

Trying to conenct postgresql with langchain.llm used - Azureopenai

from langchain.llms import AzureOpenAI

llms = AzureOpenAI( temperature=0,deployment_name="gpt3turbo".......)


toolkit = SQLDatabaseToolkit(db=db,llm=llms)


Error:

ValidationError: 1 validation error for SQLDatabaseToolkit

llm

  value is not a valid dict (type=type_error.dict)

Tried different versions of langchain


Solution:

Your question is not clear:


Please see if all the steps are correct from the beginning.


Install Packages

pip install langchain 

pip install openai

pip install psycopg2


Next create a python file called main.py and import the following:

from langchain.agents import create_sql_agent 

from langchain.agents.agent_toolkits import SQLDatabaseToolkit 

from langchain.sql_database import SQLDatabase 

from langchain.llms.openai import OpenAI 

from langchain.agents import AgentExecutor 

from langchain.agents.agent_types import AgentType

from langchain.chat_models import ChatOpenAI


Connect to database:


pg = f"postgresql+psycopg2://{username}:{password}@{host}:{port}/{mydatabase}"


Set database:

db = SQLDatabase.from_uri(pg_uri)


Once you have your OPENAI_API_KEY:

OPENAI_API_KEY = "your OpenAI key"


Define your llm model:

gpt = OpenAI(temperature=0, openai_api_key=OPENAI_API_KEY, model_name='gpt-3.5-turbo')


Toolkit should be:

toolkit = SQLDatabaseToolkit(db=db, llm=gpt)


Credit to @DishenWang for the complete article:

>https://medium.com/dataherald/how-to-connect-llm-to-sql-database-with-langchain-sqlagent-48635fddaa74


Suggested blogs:

>How to check null in jQuery?

>How is the value of the path column under the wagtailcore_page table populated?

>Why VSCode indicate an error on using {{ }}?

>Fix the python-decouple issue in Django

>Address the N+1 problem in Django with prefetch

>How can I retrieve all customers' bookings by their username/ID?

>How to solve Static Files not being found in Django?


Ritu Singh

Ritu Singh

Submit
0 Answers