richardr1126
commited on
Commit
•
560d821
1
Parent(s):
3c3d942
Better chatgpt prompt
Browse files
app.py
CHANGED
@@ -130,7 +130,7 @@ def extract_db_code(text):
|
|
130 |
return [match.strip() for match in matches]
|
131 |
|
132 |
def generate_dummy_db(db_info, question):
|
133 |
-
pre_prompt = "Generate a SQLite database with dummy data for this database from the DB Layout. Make sure you add dummy data relevant to the Question
|
134 |
prompt = pre_prompt + "\n\nDB Layout:" + db_info + "\n\nQuestion: " + question
|
135 |
|
136 |
while True:
|
@@ -138,7 +138,7 @@ def generate_dummy_db(db_info, question):
|
|
138 |
response = openai.ChatCompletion.create(
|
139 |
model="gpt-3.5-turbo",
|
140 |
messages=[
|
141 |
-
{"role": "system", "content": "You are a SQLite dummy database generator. 1. You will create the specified dummy database. 2. Insert the dummy data. and 3. Output the only the code in a SQL code block."},
|
142 |
{"role": "user", "content": prompt}
|
143 |
],
|
144 |
#temperature=0.7,
|
@@ -217,13 +217,16 @@ def generate(input_message: str, db_info="", temperature=0.2, top_p=0.9, top_k=0
|
|
217 |
do_sample=do_sample,
|
218 |
)
|
219 |
|
|
|
220 |
db_code_future = None
|
221 |
if num_return_sequences > 1:
|
222 |
with concurrent.futures.ThreadPoolExecutor() as executor:
|
223 |
db_code_future = executor.submit(generate_dummy_db, db_info, input_message)
|
224 |
|
|
|
225 |
tokens = m.generate(**generate_kwargs)
|
226 |
|
|
|
227 |
if db_code_future:
|
228 |
db_code = db_code_future.result()
|
229 |
|
|
|
130 |
return [match.strip() for match in matches]
|
131 |
|
132 |
def generate_dummy_db(db_info, question):
|
133 |
+
pre_prompt = "Generate a SQLite database with dummy data for this database from the DB Layout. Make sure you add dummy data relevant to the Question, don't write any SELECT statements or actual queries, and do not change any of the table or column names."
|
134 |
prompt = pre_prompt + "\n\nDB Layout:" + db_info + "\n\nQuestion: " + question
|
135 |
|
136 |
while True:
|
|
|
138 |
response = openai.ChatCompletion.create(
|
139 |
model="gpt-3.5-turbo",
|
140 |
messages=[
|
141 |
+
{"role": "system", "content": "You are a SQLite dummy database generator. 1. You will create the specified dummy database with the same exact table and column names used in the DB Layout. 2. Insert the dummy data. and 3. Output the only the code in a SQL code block."},
|
142 |
{"role": "user", "content": prompt}
|
143 |
],
|
144 |
#temperature=0.7,
|
|
|
217 |
do_sample=do_sample,
|
218 |
)
|
219 |
|
220 |
+
# Generate dummy database code if num_return_sequences > 1 in a separate thread
|
221 |
db_code_future = None
|
222 |
if num_return_sequences > 1:
|
223 |
with concurrent.futures.ThreadPoolExecutor() as executor:
|
224 |
db_code_future = executor.submit(generate_dummy_db, db_info, input_message)
|
225 |
|
226 |
+
# Generate the SQL query
|
227 |
tokens = m.generate(**generate_kwargs)
|
228 |
|
229 |
+
# Wait for the dummy database code to finish generating
|
230 |
if db_code_future:
|
231 |
db_code = db_code_future.result()
|
232 |
|