Spaces:
Sleeping
Sleeping
fun 3 menos restrictivo
Browse files
app.py
CHANGED
|
@@ -17,7 +17,7 @@ def format_prompt(message, history):
|
|
| 17 |
return prompt
|
| 18 |
|
| 19 |
def replace_variables_with_placeholders(query):
|
| 20 |
-
#
|
| 21 |
return re.sub(r"= '.*?'", "= ?", query)
|
| 22 |
|
| 23 |
def generate(prompt, history, temperature=0.2, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0):
|
|
@@ -47,13 +47,16 @@ def generate(prompt, history, temperature=0.2, max_new_tokens=256, top_p=0.95, r
|
|
| 47 |
|
| 48 |
for response in stream:
|
| 49 |
output += response.token.text
|
| 50 |
-
# Verificar si la respuesta contiene la consulta deseada
|
| 51 |
-
if "SELECT" in output.upper() and "FROM" in output.upper():
|
| 52 |
-
# Reemplazar variables en la cláusula WHERE con ?
|
| 53 |
-
output = replace_variables_with_placeholders(output)
|
| 54 |
-
break
|
| 55 |
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
mychatbot = gr.Chatbot(
|
| 59 |
avatar_images=["./user.png", "./botm.png"],
|
|
|
|
| 17 |
return prompt
|
| 18 |
|
| 19 |
def replace_variables_with_placeholders(query):
|
| 20 |
+
# Reemplazar variables en la cláusula WHERE con ?
|
| 21 |
return re.sub(r"= '.*?'", "= ?", query)
|
| 22 |
|
| 23 |
def generate(prompt, history, temperature=0.2, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0):
|
|
|
|
| 47 |
|
| 48 |
for response in stream:
|
| 49 |
output += response.token.text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
# Reemplazar variables en la cláusula WHERE con ?
|
| 52 |
+
final_output = replace_variables_with_placeholders(output)
|
| 53 |
+
|
| 54 |
+
# Verificar si la respuesta contiene la consulta deseada y devolver solo la consulta
|
| 55 |
+
if "SELECT" in final_output.upper() and "FROM" in final_output.upper():
|
| 56 |
+
final_output = final_output.strip().split("\n")[0]
|
| 57 |
+
final_output = "\n".join(line for line in output.split("\n") if line.strip().startswith(("SELECT", "FROM", "JOIN", "WHERE")))
|
| 58 |
+
|
| 59 |
+
yield final_output.strip()
|
| 60 |
|
| 61 |
mychatbot = gr.Chatbot(
|
| 62 |
avatar_images=["./user.png", "./botm.png"],
|