diff --git a/interpreter/core/computer/terminal/languages/jupyter_language.py b/interpreter/core/computer/terminal/languages/jupyter_language.py index 93bbdf78..9e735357 100644 --- a/interpreter/core/computer/terminal/languages/jupyter_language.py +++ b/interpreter/core/computer/terminal/languages/jupyter_language.py @@ -44,9 +44,9 @@ def __init__(self, computer): backend = "Agg" code = f""" - import matplotlib - matplotlib.use('{backend}') - """ +import matplotlib +matplotlib.use('{backend}') + """.strip() for _ in self.run(code): pass @@ -67,7 +67,11 @@ def run(self, code): ### OFFICIAL OPEN INTERPRETER GOVERNMENT ISSUE SKILL LIBRARY ### ################################################################ - functions = string_to_python(code) + try: + functions = string_to_python(code) + except: + # Non blocking + functions = {} skill_library_path = self.computer.skills.path for filename, code in functions.items(): with open(f"{skill_library_path}/{filename}.py", "w") as file: @@ -400,18 +404,20 @@ def string_to_python(code_as_string): # Check for function definitions elif isinstance(node, ast.FunctionDef): func_info = { - 'name': node.name, - 'docstring': ast.get_docstring(node), - 'body': '\n '.join(ast.unparse(stmt) for stmt in node.body[1:]) # Excludes the docstring + "name": node.name, + "docstring": ast.get_docstring(node), + "body": "\n ".join( + ast.unparse(stmt) for stmt in node.body[1:] + ), # Excludes the docstring } functions.append(func_info) for func in functions: # Consolidating import statements and function definition - function_content = '\n'.join(import_statements) + '\n\n' + function_content = "\n".join(import_statements) + "\n\n" function_content += f"def {func['name']}():\n \"\"\"{func['docstring']}\"\"\"\n {func['body']}\n" - + # Adding to dictionary - functions_dict[func['name']] = function_content + functions_dict[func["name"]] = function_content - return functions_dict \ No newline at end of file + return functions_dict diff --git a/tests/test_interpreter.py b/tests/test_interpreter.py index 9f07b47a..84131b63 100644 --- a/tests/test_interpreter.py +++ b/tests/test_interpreter.py @@ -367,10 +367,11 @@ def test_hello_world(): hello_world_message = f"Please reply with just the words {hello_world_response} and nothing else. Do not run code. No confirmation just the text." - interpreter.chat(hello_world_message) - messages = interpreter.messages + messages = interpreter.chat(hello_world_message) - assert messages == [{"role": "assistant", "type": "message", "content": hello_world_response}] + assert messages == [ + {"role": "assistant", "type": "message", "content": hello_world_response} + ] def test_math(): @@ -479,25 +480,6 @@ def test_markdown(): ) -def test_system_message_appending(): - ping_system_message = ( - "Respond to a `ping` with a `pong`. No code. No explanations. Just `pong`." - ) - - ping_request = "ping" - pong_response = "pong" - - interpreter.system_message += ping_system_message - - interpreter.chat(ping_request) - messages = interpreter.messages - - assert messages == [ - {"role": "user", "type": "message", "content": ping_request}, - {"role": "assistant", "type": "message", "content": pong_response}, - ] - - def test_reset(): # make sure that interpreter.reset() clears out the messages Array assert interpreter.messages == []