Skip to content

Commit 18280bf

Browse files
committed
Default to importing the computer API
1 parent 34fd952 commit 18280bf

File tree

2 files changed

+16
-2
lines changed
  • interpreter

2 files changed

+16
-2
lines changed

interpreter/core/computer/terminal/terminal.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
11
import json
2+
import os
23
import time
34

45
from ..utils.recipient_utils import parse_for_recipient
56
from .languages.applescript import AppleScript
67
from .languages.html import HTML
8+
from .languages.java import Java
79
from .languages.javascript import JavaScript
810
from .languages.powershell import PowerShell
911
from .languages.python import Python
1012
from .languages.r import R
1113
from .languages.react import React
1214
from .languages.ruby import Ruby
1315
from .languages.shell import Shell
14-
from .languages.java import Java
1516

1617
# Should this be renamed to OS or System?
1718

19+
import_computer_api_code = """
20+
import os
21+
os.environ["INTERPRETER_COMPUTER_API"] = "False" # To prevent infinite recurring import of the computer API
22+
23+
import time
24+
import datetime
25+
from interpreter import interpreter
26+
27+
computer = interpreter.computer
28+
""".strip()
29+
1830

1931
class Terminal:
2032
def __init__(self, computer):
@@ -48,13 +60,14 @@ def run(self, language, code, stream=False, display=False):
4860
self.computer.import_computer_api
4961
and not self.computer._has_imported_computer_api
5062
and "computer" in code
63+
and os.getenv("INTERPRETER_COMPUTER_API", "True") != "False"
5164
):
5265
self.computer._has_imported_computer_api = True
5366
# Give it access to the computer via Python
5467
time.sleep(0.5)
5568
self.computer.run(
5669
language="python",
57-
code="import time\nimport datetime\nfrom interpreter import interpreter\ncomputer = interpreter.computer", # We ask it to use time, so
70+
code=import_computer_api_code,
5871
display=self.computer.verbose,
5972
)
6073

interpreter/terminal_interface/profiles/defaults/os.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
# Note: There are NO other browser functions — use regular `webbrowser` and `computer.display.view()` commands to view/control a real browser.
4040
4141
computer.display.view() # Shows you what's on the screen (primary display by default), returns a `pil_image` `in case you need it (rarely). To get a specific display, use the parameter screen=DISPLAY_NUMBER (0 for primary monitor 1 and above for secondary monitors). **You almost always want to do this first!**
42+
# NOTE: YOU MUST NEVER RUN image.show() AFTER computer.display.view. IT WILL AUTOMATICALLY SHOW YOU THE IMAGE. DO NOT RUN image.show().
4243
4344
computer.keyboard.hotkey(" ", "command") # Opens spotlight (very useful)
4445
computer.keyboard.write("hello")

0 commit comments

Comments
 (0)