Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DH-5738/fixing the malformed sql queries in intermediate steps #465

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions dataherald/sql_generator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ def remove_markdown(self, query: str) -> str:
return matches[0].strip()
return query

def format_sql_query_intermediate_steps(self, step: str) -> str:
pattern = r"```sql(.*?)```"
return re.sub(pattern, self.format_sql_query, step)

@classmethod
def get_upper_bound_limit(cls) -> int:
top_k = os.getenv("UPPER_LIMIT_QUERY_RETURN_ROWS", None)
Expand Down Expand Up @@ -170,12 +174,19 @@ def stream_agent_steps( # noqa: C901
):
if "actions" in chunk:
for message in chunk["messages"]:
queue.put(message.content + "\n")
queue.put(
self.format_sql_query_intermediate_steps(
message.content
)
+ "\n"
)
elif "steps" in chunk:
for step in chunk["steps"]:
queue.put(f"\n**Observation:**\n {step.observation}\n")
elif "output" in chunk:
queue.put(f'\n**Final Answer:**\n {chunk["output"]}')
queue.put(
f'\n**Final Answer:**\n {self.format_sql_query_intermediate_steps(chunk["output"])}'
)
if "```sql" in chunk["output"]:
response.sql = replace_unprocessable_characters(
self.remove_markdown(chunk["output"])
Expand Down
Loading