Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Feb 6, 2024
2 parents 92d4553 + cc285d9 commit c563e1a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 33 deletions.
28 changes: 17 additions & 11 deletions interpreter/core/computer/terminal/languages/jupyter_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down Expand Up @@ -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
return functions_dict
26 changes: 4 additions & 22 deletions tests/test_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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 == []
Expand Down

0 comments on commit c563e1a

Please sign in to comment.