Skip to content

Commit 757a7a4

Browse files
committed
change payload loading to be through temp file
1 parent 3f3c854 commit 757a7a4

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

‎rlm/environments/docker_repl.py‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,21 @@ def setup(self):
254254
)
255255

256256
def load_context(self, context_payload: dict | list | str):
257+
"""Load context by writing to a file in the mounted workspace."""
257258
if isinstance(context_payload, str):
258-
escaped = context_payload.replace("\\", "\\\\").replace('"""', '\\"\\"\\"')
259-
self.execute_code(f'context = """{escaped}"""')
259+
context_path = os.path.join(self.temp_dir, "context.txt")
260+
with open(context_path, "w") as f:
261+
f.write(context_payload)
262+
self.execute_code(
263+
"with open('/workspace/context.txt', 'r') as f:\n context = f.read()"
264+
)
260265
else:
261-
self.execute_code(f"import json; context = json.loads('{json.dumps(context_payload)}')")
266+
context_path = os.path.join(self.temp_dir, "context.json")
267+
with open(context_path, "w") as f:
268+
json.dump(context_payload, f)
269+
self.execute_code(
270+
"import json\nwith open('/workspace/context.json', 'r') as f:\n context = json.load(f)"
271+
)
262272

263273
def execute_code(self, code: str) -> REPLResult:
264274
start = time.perf_counter()

0 commit comments

Comments
 (0)