forked from islamshahil/Text-To-SQL-Using-GPT-3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpt3.py
More file actions
38 lines (31 loc) · 1.89 KB
/
gpt3.py
File metadata and controls
38 lines (31 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import json
import openai
with open('GPT_SECRET_KEY.json') as f:
data = json.load(f)
openai.api_key = data["API_KEY"]
from gpt import GPT
from gpt import Example
gpt = GPT(engine="davinci",
temperature=0.5,
max_tokens=100)
gpt.add_example(Example('Fetch unique values of DEPARTMENT from Worker table.',
'Select distinct DEPARTMENT from Worker;'))
gpt.add_example(Example('Print the first three characters of FIRST_NAME from Worker table.',
'Select substring(FIRST_NAME,1,3) from Worker;'))
gpt.add_example(Example("Find the position of the alphabet ('a') in the first name column 'Amitabh' from Worker table.",
"Select INSTR(FIRST_NAME, BINARY'a') from Worker where FIRST_NAME = 'Amitabh';"))
gpt.add_example(Example("Print the FIRST_NAME from Worker table after replacing 'a' with 'A'.",
"Select CONCAT(FIRST_NAME, ' ', LAST_NAME) AS 'COMPLETE_NAME' from Worker;"))
gpt.add_example(Example("Display the second highest salary from the Worker table.",
"Select max(Salary) from Worker where Salary not in (Select max(Salary) from Worker);"))
gpt.add_example(Example("Display the highest salary from the Worker table.",
"Select max(Salary) from Worker;"))
gpt.add_example(Example("Fetch the count of employees working in the department Admin.",
"SELECT COUNT(*) FROM worker WHERE DEPARTMENT = 'Admin';"))
gpt.add_example(Example("Get all details of the Workers whose SALARY lies between 100000 and 500000.",
"Select * from Worker where SALARY between 100000 and 500000;"))
gpt.add_example(Example("Get Salary details of the Workers",
"Select Salary from Worker"))
prompt = "Display the lowest salary from the Worker table."
output = gpt.submit_request(prompt)
output.choices[0].text