Git Product home page Git Product logo

text2sql-workshop's Introduction

Text2SQL Workshop

Using OpenAI, Langchain and Postgresql to Talk to Your Data


Overview

  • This repo demonstrates the power of Large Language Models and Generative AI for simplifying access to data: instead of querying a database using SQL, why not doing so using Natural Language?
  • text2sql is a basic Python package which ships with Langchain. It contains simple logic for connecting to a local Postgresql instance, and by leveraging Langchain's create_sql_query_chain, it obtains metadata from our local DB instances and creates multiple prompts which are executed against an LLM (in our case, OpenAI ChatGPT).
  • As a result, we are able to convert questions from Natural Language to SQL Queries that are compliant with Postgresql's dialect.

Usage

  • Create a virtual environment with your tool of choice and install the text2sql Python package
  • Once the package is installed, you can create an IPython kernel and use it in Jupyter - checkout the notebooks provided in the sandbox folder.

Example

from text2sql.core import Text2SQL

sql = Text2SQL(model = "gpt-3.5-turbo")
query = sql.query("How much do we have in total sales?")
print(query)
> SELECT SUM("Weekly_Sales") AS total_sales FROM sales

Prereqs

  • We use Docker to boot up a Postgresql DB. Just run docker-compose up -d and you should be good to go
  • To ingest data into Postgres, run text2sql/ingest.py (for simplification purposes, the package expects you to be running a local instance of Postgresql at port 5432)
  • Make sure that you properly set your OPENAI_API_KEY

Authors

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.