Skip to content

feat: introducing watsonx sql database wrapper and toolkit #97

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

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

Mateusz-Switala
Copy link
Collaborator

The goal of this PR is to add WatsonxSQLDatabase and WatsonxSQLDatabaseToolkit to langchain_ibm.

Example

from langchain_ibm.utilities.sql_database import WatsonxSQLDatabase

wx_sql_database = WatsonxSQLDatabase(connection_id=postgres_sql_connection_id,
                                     **credentials,
                                     schema="public"
                                     )

from langchain_ibm import ChatWatsonx

chat_llama = ChatWatsonx(
    watsonx_client=wx_sql_database.watsonx_client,
    model_id="mistralai/mistral-medium-2505",
    params={"max_new_tokens": 200},
)

from langchain_ibm.agent_toolkits.sql_toolkit import WatsonxSQLDatabaseToolkit


toolkit = WatsonxSQLDatabaseToolkit(db=wx_sql_database, llm=chat_llama)


from langchain import hub

prompt_template = hub.pull("langchain-ai/sql-agent-system-prompt")
system_message = prompt_template.format(dialect="PostgreSQL", top_k=5)

from langgraph.prebuilt import create_react_agent

agent_executor = create_react_agent(chat_llama, toolkit.get_tools(), prompt=system_message)


example_query = "What city in Japan has the largest population? How much it is?"

events = agent_executor.stream(
    {"messages": [("user", example_query)]},
    stream_mode="values",
)
for event in events:
    event["messages"][-1].pretty_print()

Comment on lines +27 to +31
if not isinstance(content, str) or length <= 0:
return content

if len(content) <= length:
return content
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be combined into 1 if statement using the second or unless you want to split it for some reason like clarity?

@@ -13,7 +13,11 @@ license = "MIT"
[tool.poetry.dependencies]
python = ">=3.10,<3.14"
langchain-core = "^0.3.39"
ibm-watsonx-ai = "^1.3.28"
ibm-watsonx-ai = "^1.3.32"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it be updated to 1.3.34 or it is not necessary?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants