Skip to content

wgong/gpt3sql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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