Skip to content

Commit fa8c5c2

Browse files
Fix result formatting #44
1 parent 7ebed00 commit fa8c5c2

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "sql-sidekick"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
license = "Apache-2.0 license"
55
description = "An AI assistant for SQL generation"
66
authors = [

sidekick/prompter.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
os.environ["TOKENIZERS_PARALLELISM"] = "False"
4242
os.environ["H2O_BASE_MODEL_URL"] = h2ogpt_base_model_url
4343
os.environ["H2O_BASE_MODEL_API_KEY"] = h2ogpt_base_model_key
44+
os.environ["RECOMMENDATION_MODEL_REMOTE_URL"] = h2o_remote_url
45+
os.environ["RECOMMENDATION_MODEL_API_KEY"] = h2o_key
4446

4547
def color(fore="", back="", text=None):
4648
return f"{fore}{back}{text}{Style.RESET_ALL}"
@@ -650,12 +652,12 @@ def ask(
650652
attempt = 0
651653
error_condition = lambda e: ('OperationalError'.lower() in e.lower() or 'OperationError'.lower() in e.lower() or 'Syntax error'.lower() in e.lower()) if e else False
652654
if self_correction and error_condition(err):
653-
logger.info("Attempting to auto-correct the query...")
655+
logger.info("Attempting to auto-correct the query during runtime...")
654656
while attempt !=3 and error_condition(err):
655657
try:
656658
logger.debug(f"Attempt: {attempt+1}")
657659
_tmp = err.split("\n")
658-
_err = _tmp[0].split("Error occurred :")[1] if len(_tmp) > 0 else None
660+
_err = _tmp[0].split("Error occurred:")[1] if len(_tmp) > 0 else None
659661
env_url = os.environ["RECOMMENDATION_MODEL_REMOTE_URL"]
660662
env_key = os.environ["RECOMMENDATION_MODEL_API_KEY"]
661663
corr_sql = sql_g.self_correction(input_prompt=_val, error_msg=_err, remote_url=env_url, client_key=env_key)
@@ -667,7 +669,7 @@ def ask(
667669
logger.error(f"Something went wrong:\n{e}")
668670
attempt += 1
669671
if m:
670-
_t = "\nWarning:\n".join([str(q_res), m])
672+
_t = "\n\n**Warning:**\n".join([str(q_res), m])
671673
q_res = _t
672674
elif option == "pandas":
673675
tables = extract_table_names(_val)
@@ -697,7 +699,7 @@ def ask(
697699
click.echo("Error in executing the query. Validate generated SQL and try again.")
698700
click.echo("No result to display.")
699701

700-
results.append("**Result:** \n")
702+
results.append("**Result:**\n")
701703
if q_res:
702704
# Check shape of the final result to avoid blowing up memory
703705
# Logging a quick preview of the result

sidekick/query.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -678,12 +678,12 @@ def generate_sql(
678678
max_new_tokens=512,
679679
temperature=random_temperature,
680680
top_k=5,
681-
top_p=0.9,
681+
top_p=1.0,
682682
num_beams=5,
683683
num_beam_groups=5,
684684
num_return_sequences=5,
685685
output_scores=True,
686-
do_sample=True,
686+
do_sample=False,
687687
diversity_penalty=2.0,
688688
return_dict_in_generate=True,
689689
)
@@ -714,9 +714,7 @@ def generate_sql(
714714
for idx, sorted_idx in enumerate(prob_sorted_idxs):
715715
_out = output_re.sequences[sorted_idx]
716716
res = tokenizer.decode(_out[input_length:], skip_special_tokens=True)
717-
result = res.replace("table_name", _table_name)
718-
# Remove the last semi-colon if exists at the end
719-
# we will add it later
717+
result = res.replace("table_name", _table_name).replace("```", "").strip()
720718
if result.endswith(";"):
721719
result = result.replace(";", "")
722720
if "LIMIT".lower() not in result.lower():
@@ -742,6 +740,8 @@ def generate_sql(
742740
if not _temp:
743741
res = None
744742
else:
743+
if _temp.endswith("```"):
744+
_temp = _temp.replace("```", "")
745745
_temp = _temp.split("\n```")[0].strip()
746746
# TODO Below should not happen, will have to check why its getting generated as part of response.
747747
# Not sure, if its a vllm or prompt issue.

0 commit comments

Comments
 (0)