From 8c9d027814eb898b5c226e330ac043c0948a048d Mon Sep 17 00:00:00 2001 From: Erick Martinez <38702114+erickfm@users.noreply.github.com> Date: Wed, 18 Oct 2023 10:57:38 -0700 Subject: [PATCH] Fixed newline SyntaxError (#136) * Update session.py Resolves SyntaxError: unterminated string literal issue where multi-line code strings are not processed correctly if they're not formatted in compliance with Python's string literal rules. Specifically, the interpreter fails when the code string starts with a newline right after the opening quote or doesn't use triple quotes for multi-line code snippets. This leads to an unended string literal error because the interpreter expects a complete string format as per Python syntax rules. * Fixed newline SyntaxError Added some prompting to the python tool to resolve SyntaxError: unterminated string literal where multi-line code strings are not processed correctly if they're not formatted in compliance with Python's string literal rules. Specifically, the interpreter fails when the code string starts with a newline right after the opening quote or doesn't use triple quotes for multi-line code snippets. This leads to an unended string literal error because the interpreter expects a complete string format as per Python syntax rules. --- codeinterpreterapi/session.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/codeinterpreterapi/session.py b/codeinterpreterapi/session.py index f5f12e7b..bf90eec2 100644 --- a/codeinterpreterapi/session.py +++ b/codeinterpreterapi/session.py @@ -108,6 +108,9 @@ def _tools(self, additional_tools: list[BaseTool]) -> list[BaseTool]: description="Input a string of code to a ipython interpreter. " "Write the entire code in a single string. This string can " "be really long, so you can use the `;` character to split lines. " + "Start your code on the same line as the opening quote. " + "Do not start your code with a line break. " + "For example, do 'import numpy', not '\\nimport numpy'." "Variables are preserved between runs. " + ( (