langchain icon indicating copy to clipboard operation
langchain copied to clipboard

Docs to include LLM before creating SQL Database Agent

Open vikramnr opened this issue 1 year ago • 1 comments

In the documentation it is mentioned to create toolkit without LLM agent, but its one of the required fields for toolkit.

Instead of this,

toolkit = SQLDatabaseToolkit(db=db)

agent_executor = create_sql_agent(
    llm=OpenAI(temperature=0),
    toolkit=toolkit,
    verbose=True
)

it should be this

llm=OpenAI(temperature=0)
toolkit = SQLDatabaseToolkit(db=db,llm=llm)

agent_executor = create_sql_agent(
    llm=llm,
    toolkit=toolkit,
    verbose=True
)

Please do correct me if I'm wrong

Links to the docs https://python.langchain.com/en/latest/modules/agents/toolkits/examples/sql_database.html

vikramnr avatar Apr 29 '23 19:04 vikramnr

Still got an error. :( image

xiaohui-hiwintech avatar May 22 '23 03:05 xiaohui-hiwintech

I'm using the below version & SQL database, not sure if that provides more insight.

I'll look into the base class and see if I'm missing something

image image

vikramnr avatar May 25 '23 07:05 vikramnr

I was having the same problem and then I noticed that some of the error was pointing to parameters for the language model. I solved the issue but adding the API key. Is your API key in the code? Or were you just testing the rest like I was?

Statisticonomicon avatar Jun 19 '23 17:06 Statisticonomicon

I think you should try importing from langchain.chat_models import ChatOpenAI instead. What works for me is the following:

db = SQLDatabase.from_uri(f"postgresql+psycopg2://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_NAME}")

llm = ChatOpenAI(model_id="gpt-3.5-turbo-16k", temperature=0)

toolkit = SQLDatabaseToolkit(db=db, llm=llm) agent_executor = create_sql_agent( llm=llm, toolkit=toolkit, verbose=True )

ChelcieDeAlmeida avatar Aug 24 '23 10:08 ChelcieDeAlmeida

Hi, @vikramnr! I'm Dosu, and I'm here to help the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.

From what I understand, the issue you raised is about a discrepancy in the documentation for creating a SQL Database Agent. You suggested that the documentation should include the requirement of including the LLM agent in the toolkit. There have been some comments from other users experiencing similar issues and providing suggestions for resolving the problem, such as checking the base class and adding the API key. One user also suggested trying a different import statement for the ChatOpenAI module.

Before we close this issue, we wanted to check with you if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days.

Thank you for your contribution to the LangChain repository!

dosubot[bot] avatar Nov 23 '23 16:11 dosubot[bot]