Skip to content

Commit 3bd2318

Browse files
Fix cosmetics: Reindent code n basic syntax highlighting #29
1 parent 0b394f0 commit 3bd2318

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

sidekick/prompter.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import click
88
import openai
9+
import sqlparse
910
import toml
1011
import torch
1112
from colorama import Back as B
@@ -474,8 +475,9 @@ def query_api(
474475
[res := res.replace(s, '"') for s in "‘`’'" if s in res]
475476
logger.info(f"Input query: {question}")
476477
logger.info(f"Generated response:\n\n{res}")
477-
478-
results.extend([f"**Generated response for question,**\n{question}\n", res, "\n"])
478+
pretty_sql = sqlparse.format(res, reindent=True, keyword_case="upper")
479+
syntax_highlight = f"""``` sql\n{pretty_sql}\n```\n\n"""
480+
results.extend([f"**Generated response for question,**\n{question}\n", syntax_highlight, "\n"])
479481
logger.info(f"Alternate responses:\n\n{alt_res}")
480482

481483
exe_sql = click.prompt("Would you like to execute the generated SQL (y/n)?") if is_command else "y"

sidekick/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def generate_sql(
316316
)
317317
else:
318318
res = str(res).split("Explanation:", 1)[0].strip()
319-
sqlglot.transpile(res)
319+
res = sqlglot.transpile(res, read=_dialect)
320320
except (sqlglot.errors.ParseError, ValueError, RuntimeError) as e:
321321
logger.info("We did the best we could, there might be still be some error:\n")
322322
logger.info(f"Realized query so far:\n {res}")

0 commit comments

Comments
 (0)