Skip to content

wgong/gpt3sql

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
app
 
 
 
 
 
 
 
 
 
 
 
 

gpt3sql

Use GPT3 to generate SQL from text

Develop a streamlit app to explore GPT-3 Codex capability (https://beta.openai.com/docs/guides/code/introduction) in terms of SQL generation

Get started

Get your own API Key at https://beta.openai.com/, save it into a new file at app/cfg/api_key.yaml (make sure this file is gitignored):

OPENAI_API_KEY: <ENTER-Your-Own-API-Key>

Run the following commands a shell terminal:

$ pip install -r requirements.txt
$ cd app
$ streamlit run app.py

Example

Prompt submitted at Playground

"""
Table customers, columns = [CustomerId, FirstName, LastName, Company, Address, City, State, Country, PostalCode, Phone, Fax, Email, SupportRepId]
Create a SQLite query for all customers in Texas named Jane
"""

The Python code:

import os
import openai

openai.api_key = os.getenv("OPENAI_API_KEY")

# POST /v1/completions

response = openai.Completion.create(
  model="davinci-instruct-beta",
  prompt="\"\"\"\nTable customers, columns = [CustomerId, FirstName, LastName,  State]\nCreate a SQLite query for all customers in Texas named Jane\n\"\"\"\n\n\n",
  temperature=0,
  max_tokens=256,
  top_p=1,
  frequency_penalty=0,
  presence_penalty=0
)

Response:

print(response["choices"][0]["text"])

SELECT * FROM customers WHERE State='TX' AND FirstName='Jane'

References

OpenAI

Streamlit

SQL

Others

Credits

About

use GPT3 to generate SQL from text

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published