From 6eef5b0fab3ca12b0c7be900e827949d9a5b6a1a Mon Sep 17 00:00:00 2001 From: Yogananda Muthaiah Date: Sun, 1 Dec 2024 09:55:23 +0100 Subject: [PATCH] Update chapter13.md --- chapter13.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/chapter13.md b/chapter13.md index 8b13789..49645c8 100644 --- a/chapter13.md +++ b/chapter13.md @@ -1 +1,19 @@ +## Chapter 13: Database Integration +With LangChain, you can integrate with databases and build systems that answer questions based on structured data. +``` +from langchain import OpenAI, SQLDatabase, SQLDatabaseChain + +# +db = SQLDatabase.from_uri("sqlite:///chinook.db") + +# LLM +llm = OpenAI(temperature=0) + +# +db_chain = SQLDatabaseChain(llm=llm, database=db, verbose=True) + +# +query = "How many tracks are there in the album with ID 1?" +print(db_chain.run(query)) +```