Skip to content

Commit 5d3b827

Browse files
authored
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.
1 parent c3c91b4 commit 5d3b827

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

codeinterpreterapi/session.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ def _tools(self, additional_tools: list[BaseTool]) -> list[BaseTool]:
108108
description="Input a string of code to a ipython interpreter. "
109109
"Write the entire code in a single string. This string can "
110110
"be really long, so you can use the `;` character to split lines. "
111+
"Start your code on the same line as the opening quote. "
112+
"Do not start your code with a line break. "
113+
"For example, do 'import numpy', not '\\nimport numpy'."
111114
"Variables are preserved between runs. "
112115
+ (
113116
(

0 commit comments

Comments
 (0)