Skip to content

Commit f1eb5f2

Browse files
committed
Improved computer syncing
1 parent f66f5d1 commit f1eb5f2

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

interpreter/core/respond.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,15 +296,16 @@ def respond(interpreter):
296296
computer_dict = interpreter.computer.to_dict()
297297
if "_hashes" in computer_dict:
298298
computer_dict.pop("_hashes")
299-
if computer_dict:
300-
computer_json = json.dumps(computer_dict)
301-
sync_code = f"""import json\ncomputer.load_dict(json.loads('''{computer_json}'''))"""
302-
interpreter.computer.run("python", sync_code)
299+
if "system_message" in computer_dict:
300+
computer_dict.pop("system_message")
301+
computer_json = json.dumps(computer_dict)
302+
sync_code = f"""import json\ncomputer.load_dict(json.loads('''{computer_json}'''))"""
303+
interpreter.computer.run("python", sync_code)
303304
except Exception as e:
304305
if interpreter.debug:
305306
raise
306307
print(str(e))
307-
print("Continuing...")
308+
print("Failed to sync iComputer with your Computer. Continuing...")
308309

309310
## ↓ CODE IS RUN HERE
310311

@@ -319,7 +320,15 @@ def respond(interpreter):
319320
# sync up the interpreter's computer with your computer
320321
result = interpreter.computer.run(
321322
"python",
322-
"import json\ncomputer_dict = computer.to_dict()\nif computer_dict:\n if '_hashes' in computer_dict:\n computer_dict.pop('_hashes')\n print(json.dumps(computer_dict))",
323+
"""
324+
import json
325+
computer_dict = computer.to_dict()
326+
if '_hashes' in computer_dict:
327+
computer_dict.pop('_hashes')
328+
if "system_message" in computer_dict:
329+
computer_dict.pop("system_message")
330+
print(json.dumps(computer_dict))
331+
""",
323332
)
324333
result = result[-1]["content"]
325334
interpreter.computer.load_dict(
@@ -329,7 +338,7 @@ def respond(interpreter):
329338
if interpreter.debug:
330339
raise
331340
print(str(e))
332-
print("Continuing.")
341+
print("Failed to sync your Computer with iComputer. Continuing.")
333342

334343
# yield final "active_line" message, as if to say, no more code is running. unlightlight active lines
335344
# (is this a good idea? is this our responsibility? i think so — we're saying what line of code is running! ...?)

0 commit comments

Comments
 (0)