Skip to content

Commit

Permalink
Harrison/sql db chain (#641)
Browse files Browse the repository at this point in the history
Co-authored-by: Bruno Bornsztein <bruno.bornsztein@gmail.com>
  • Loading branch information
hwchase17 and bborn authored Jan 18, 2023
1 parent b550f57 commit 6be5f4e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
14 changes: 11 additions & 3 deletions docs/modules/chains/examples/sqlite.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@
"metadata": {},
"outputs": [],
"source": [
"from langchain.chains.sql_database.base import SQLDatabaseSequentialChain"
"from langchain.chains import SQLDatabaseSequentialChain"
]
},
{
Expand All @@ -293,14 +293,22 @@
"\n",
"\u001b[1m> Entering new SQLDatabaseSequentialChain chain...\u001b[0m\n",
"Table names to use:\n",
"\u001b[33;1m\u001b[1;3m['Employee', 'Customer']\u001b[0m\n",
"\u001b[33;1m\u001b[1;3m['Customer', 'Employee']\u001b[0m\n",
"\n",
"\u001b[1m> Entering new SQLDatabaseChain chain...\u001b[0m\n",
"How many employees are also customers? \n",
"SQLQuery:\u001b[32;1m\u001b[1;3m SELECT COUNT(*) FROM Customer c INNER JOIN Employee e ON c.SupportRepId = e.EmployeeId;\u001b[0m\n",
"SQLResult: \u001b[33;1m\u001b[1;3m[(59,)]\u001b[0m\n",
"Answer:\u001b[32;1m\u001b[1;3m There are 59 employees who are also customers.\u001b[0m\n",
"\u001b[1m> Finished chain.\u001b[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n"
]
},
{
"data": {
"text/plain": [
"' 0 employees are also customers.'"
"' There are 59 employees who are also customers.'"
]
},
"execution_count": 5,
Expand Down
6 changes: 5 additions & 1 deletion langchain/chains/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
from langchain.chains.qa_with_sources.base import QAWithSourcesChain
from langchain.chains.qa_with_sources.vector_db import VectorDBQAWithSourcesChain
from langchain.chains.sequential import SequentialChain, SimpleSequentialChain
from langchain.chains.sql_database.base import SQLDatabaseChain
from langchain.chains.sql_database.base import (
SQLDatabaseChain,
SQLDatabaseSequentialChain,
)
from langchain.chains.transform import TransformChain
from langchain.chains.vector_db_qa.base import VectorDBQA

Expand All @@ -35,4 +38,5 @@
"TransformChain",
"MapReduceChain",
"OpenAIModerationChain",
"SQLDatabaseSequentialChain",
]
4 changes: 3 additions & 1 deletion langchain/chains/sql_database/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ def from_llm(
**kwargs: Any,
) -> SQLDatabaseSequentialChain:
"""Load the necessary chains."""
sql_chain = SQLDatabaseChain(llm=llm, database=database, prompt=query_prompt)
sql_chain = SQLDatabaseChain(
llm=llm, database=database, prompt=query_prompt, **kwargs
)
decider_chain = LLMChain(
llm=llm, prompt=decider_prompt, output_key="table_names"
)
Expand Down

0 comments on commit 6be5f4e

Please sign in to comment.