langchain icon indicating copy to clipboard operation
langchain copied to clipboard

Using the SQL Database Agent with inference from OpenAI gpt-3.5-turbo model.

Open ophirbh opened this issue 1 year ago • 6 comments

Hey guys, wanted to ask if I can use the SQL Database Agent agent and get the inference from OpenAI gpt-3.5-turbo? And if so, how can I do that?

Tried to replace the llm argument on the initialization of the agent executor from OpenAI to OpenAIChat and a bunch of other stuff. But none seems to work.

Thanks!

ophirbh avatar Apr 29 '23 12:04 ophirbh

Add model_name="gpt-3.5-turbo" to OpenAI attributes. For reference, this is the SQL Database Agent code with the change:

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


db = SQLDatabase.from_uri("sqlite:///../../../../notebooks/Chinook.db")
toolkit = SQLDatabaseToolkit(db=db)

agent_executor = create_sql_agent(
    llm=OpenAI(temperature=0, model_name="gpt-3.5-turbo"),
    toolkit=toolkit,
    verbose=True
)

IlyaMichlin avatar Apr 29 '23 16:04 IlyaMichlin

Hey. Thanks for your reply! I tried the change you suggested (that was one of the "bunch of other stuff" I mentioned), but it did not work for me.

Got this: raise OutputParserException(f"Could not parse LLM output: {text}") langchain.schema.OutputParserException: Could not parse LLM output: Action: list_tables_sql_db, ""

Did you ran it and it worked for you?

ophirbh avatar Apr 29 '23 23:04 ophirbh

Hey did your issue got resolved? Facing the same issue. Any help appreciated.

tirtharajTalukdar avatar May 24 '23 07:05 tirtharajTalukdar

Any recommendations or workarounds to solve this issue?

giyaseddin avatar May 27 '23 01:05 giyaseddin

I edited the prompt of the SQL agent by appending this string to the SQL_PREFIX

...
Always adhere to the format and don't return empty names or half responses.

And it seems to work while reasoning with ReAct responses.

Should we open a PR for it? @hwchase17

giyaseddin avatar May 27 '23 01:05 giyaseddin

@giyaseddin putting new sql prefix prompt like you provided worked sometimes but not always for my case. Still got OutputParserException(f"Could not parse LLM output: {text}")

axacheng avatar May 27 '23 04:05 axacheng

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

From what I understand, you were having trouble using the SQL Database Agent with the OpenAI gpt-3.5-turbo model. You mentioned that you tried different approaches, including adding model_name="gpt-3.5-turbo" to the OpenAI attributes, but it didn't work for you. Another user suggested editing the prompt of the SQL agent, which seemed to work for them. It's great to hear that the issue has been resolved!

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 this issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days.

Thank you for your contribution, and please don't hesitate to reach out if you have any further questions or concerns!

dosubot[bot] avatar Sep 17 '23 17:09 dosubot[bot]