Files
langchain/examples/sqlite.ipynb
T
2022-10-27 23:21:47 -07:00

1.9 KiB

This uses the example Chinook database. To set it up follow the instructions on https://database.guide/2-sample-databases-sqlite/, placing the .db file in a notebooks folder at the root of this repository.

In [1]:
from langchain import OpenAI, SQLDatabase, SQLDatabaseChain
In [2]:
db = SQLDatabase.from_uri("sqlite:///../notebooks/Chinook.db")
llm = OpenAI(temperature=0)
db_chain = SQLDatabaseChain(llm=llm, database=db)
In [3]:
db_chain.query("How many employees are there?")
Out [3]:
 SELECT COUNT(*) FROM Employee
[(8,)]
' There are 8 employees.'
In [ ]: