Files
langchain/examples/sqlite.ipynb
T
2022-11-03 00:41:07 -07:00

2.1 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, verbose=True)
In [3]:
db_chain.query("How many employees are there?")
Out [3]:
 SELECT COUNT(*) FROM Employee
SQLResult: [(8,)]
Answer: There are 8 employees.
' There are 8 employees.'
In [ ]: