Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jacoblee93/langchain-chat-sql
https://github.com/jacoblee93/langchain-chat-sql
Last synced: 9 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/jacoblee93/langchain-chat-sql
- Owner: jacoblee93
- License: mit
- Created: 2023-10-22T19:43:08.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-10T10:38:20.000Z (12 months ago)
- Last Synced: 2024-10-04T04:18:42.867Z (about 1 month ago)
- Language: TypeScript
- Homepage: https://langchain-chat-sql.vercel.app
- Size: 2.72 MB
- Stars: 12
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 🦜️🔗 Chat over SQL
This app demonstrates how to query a SQL database using natural language.
It queries a [Neon DB](https://neon.tech/)-hosted instance of the popular demo Chinook database using [LangChain.js](https://js.langchain.com/) and OpenAI's `gpt-3.5-turbo` model to generate SQL queries.
You can watch the accompanying [Neon DB Developer Days talk here](https://www.loom.com/share/d3af5d50b82c44fd8ced3b9b5244bcb1?sid=e6945413-f68e-423c-b170-7d351d2d6119) to learn more about the prompt and chain, or check out a [live Vercel deployment here](https://langchain-chat-sql.vercel.app).
## Setup
First, you'll need to create an empty [Neon DB instance](https://neon.tech/).
Using your credentials, run the following commands to bootstrap the DB and a readonly user that the LLM will use to run generated queries:
```sql
psql postgres://:@/ -f bootstrap.sqlpsql postgres://:@/ -c "CREATE ROLE llm WITH LOGIN PASSWORD '';"
psql postgres://:@/ -c "GRANT CONNECT ON DATABASE TO llm;"
psql postgres://:@/ -c "GRANT SELECT ON ALL TABLES IN SCHEMA public TO llm;"
```You can modify the last step to only give read access to certain tables, as well as allow insert/update access
to specific tables, if desired.Next, copy the `.env.example` file to `.env.local` and populate your `OPENAI_API_KEY` and Neon connection strings. To enable
tracing, you can enter your [LangSmith](https://smith.langchain.com/) keys as well.Finally, run `yarn` to install the required dependencies.
## Usage
Run `yarn dev` to start this app locally.
The database simulates a media store and contains information on employees, customers, records, and transactions. You can learn more about it in [the GitHub repo](https://github.com/lerocha/chinook-database).
Here are some traces for example queries you can ask:
- `Who works here?`
https://smith.langchain.com/public/6d9e466d-a272-4dae-89b6-56e0686fc652/r
- `How many customers are from Germany?`
https://smith.langchain.com/public/b9c83439-e12c-4ca1-97b1-7a71ba6a8539/r
## Thank you!
Check out the following links for more:
- Neon DB: https://neon.tech/
- LangChainJS: https://github.com/langchain-ai/langchainjs
- LangSmith: https://smith.langchain.com/
- Chinook DB: https://github.com/lerocha/chinook-database
- Accompanying talk: https://www.loom.com/share/d3af5d50b82c44fd8ced3b9b5244bcb1?sid=e6945413-f68e-423c-b170-7d351d2d6119