Skip to content

Commit 8293217

Browse files
committed
Update base.py
move .strip() as part of the _extract_python_code()
1 parent d49f09e commit 8293217

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/vanna/base/base.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,9 @@ def generate_question(self, sql: str, **kwargs) -> str:
689689
return response
690690

691691
def _extract_python_code(self, markdown_string: str) -> str:
692+
# Strip whitespace to avoid indentation errors in LLM-generated code
693+
markdown_string = markdown_string.strip()
694+
692695
# Regex pattern to match Python code blocks
693696
pattern = r"```[\w\s]*python\n([\s\S]*?)```|```([\s\S]*?)```"
694697

@@ -734,7 +737,7 @@ def generate_plotly_code(
734737

735738
plotly_code = self.submit_prompt(message_log, kwargs=kwargs)
736739

737-
return self._sanitize_plotly_code(self._extract_python_code(plotly_code.strip()))
740+
return self._sanitize_plotly_code(self._extract_python_code(plotly_code))
738741

739742
# ----------------- Connect to Any Database to run the Generated SQL ----------------- #
740743

0 commit comments

Comments
 (0)