Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

community: Set default value for _ListSQLDatabaseToolInput tool_input #20409

Conversation

os1ma
Copy link
Contributor

@os1ma os1ma commented Apr 13, 2024

Description:

_ListSQLDatabaseToolInput raise error if model returns {}.
For example, gpt-4-turbo returns {} with SQL Agent initialized by create_sql_agent.

So, I set default value "" for _ListSQLDatabaseToolInput tool_input.

This is actually a gpt-4-turbo issue, not a LangChain issue, but I thought it would be helpful to set a default value "".

This problem is discussed in detail in the following Issue.

Issue: #20405

Dependencies: none

Sorry, I did not add or change the test code, as tests for this components was not exist .

However, I have tested the following code based on the SQL Agent Document, to make sure it works.

from langchain_community.agent_toolkits.sql.base import create_sql_agent
from langchain_community.utilities.sql_database import SQLDatabase
from langchain_openai import ChatOpenAI

db = SQLDatabase.from_uri("sqlite:///Chinook.db")
llm = ChatOpenAI(model="gpt-4-turbo", temperature=0)
agent_executor = create_sql_agent(llm, db=db, agent_type="openai-tools", verbose=True)
result = agent_executor.invoke("List the total sales per country. Which country's customers spent the most?")
print(result["output"])

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Apr 13, 2024
Copy link

vercel bot commented Apr 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Visit Preview Apr 13, 2024 8:54am

@dosubot dosubot bot added 🔌: postgres Related to postgres integrations 🤖:improvement Medium size change to existing code to handle new use-cases labels Apr 13, 2024
@RadientBrain
Copy link

@hwchase17 bro, this resolves the bug mentioned in #20405 , Kindly look into this

@dosubot dosubot bot added the lgtm PR looks good. Use to confirm that a PR is ready for merging. label Apr 13, 2024
@baskaryan baskaryan merged commit 0758da8 into langchain-ai:master Apr 13, 2024
60 checks passed
@RadientBrain
Copy link

RadientBrain commented Apr 14, 2024

Thank you @baskaryan for merging and @os1ma for creating this PR

junkeon pushed a commit to UpstageAI/langchain that referenced this pull request Apr 16, 2024
…l_input (langchain-ai#20409)

**Description:**

`_ListSQLDatabaseToolInput` raise error if model returns `{}`.
For example, gpt-4-turbo returns `{}` with SQL Agent initialized by
`create_sql_agent`.

So, I set default value `""` for `_ListSQLDatabaseToolInput` tool_input.

This is actually a gpt-4-turbo issue, not a LangChain issue, but I
thought it would be helpful to set a default value `""`.

This problem is discussed in detail in the following Issue.

**Issue:** langchain-ai#20405

**Dependencies:** none

Sorry, I did not add or change the test code, as tests for this
components was not exist .

However, I have tested the following code based on the [SQL Agent
Document](https://python.langchain.com/docs/use_cases/sql/agents/), to
make sure it works.

```
from langchain_community.agent_toolkits.sql.base import create_sql_agent
from langchain_community.utilities.sql_database import SQLDatabase
from langchain_openai import ChatOpenAI

db = SQLDatabase.from_uri("sqlite:///Chinook.db")
llm = ChatOpenAI(model="gpt-4-turbo", temperature=0)
agent_executor = create_sql_agent(llm, db=db, agent_type="openai-tools", verbose=True)
result = agent_executor.invoke("List the total sales per country. Which country's customers spent the most?")
print(result["output"])
```
hinthornw pushed a commit that referenced this pull request Apr 26, 2024
…l_input (#20409)

**Description:**

`_ListSQLDatabaseToolInput` raise error if model returns `{}`.
For example, gpt-4-turbo returns `{}` with SQL Agent initialized by
`create_sql_agent`.

So, I set default value `""` for `_ListSQLDatabaseToolInput` tool_input.

This is actually a gpt-4-turbo issue, not a LangChain issue, but I
thought it would be helpful to set a default value `""`.

This problem is discussed in detail in the following Issue.

**Issue:** #20405

**Dependencies:** none

Sorry, I did not add or change the test code, as tests for this
components was not exist .

However, I have tested the following code based on the [SQL Agent
Document](https://python.langchain.com/docs/use_cases/sql/agents/), to
make sure it works.

```
from langchain_community.agent_toolkits.sql.base import create_sql_agent
from langchain_community.utilities.sql_database import SQLDatabase
from langchain_openai import ChatOpenAI

db = SQLDatabase.from_uri("sqlite:///Chinook.db")
llm = ChatOpenAI(model="gpt-4-turbo", temperature=0)
agent_executor = create_sql_agent(llm, db=db, agent_type="openai-tools", verbose=True)
result = agent_executor.invoke("List the total sales per country. Which country's customers spent the most?")
print(result["output"])
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:improvement Medium size change to existing code to handle new use-cases lgtm PR looks good. Use to confirm that a PR is ready for merging. 🔌: postgres Related to postgres integrations size:XS This PR changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants