Skip to content

Commit 18a9368

Browse files
authored
change payload loading to be through temp file (#47)
1 parent 2b1561a commit 18a9368

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
@@ -257,11 +257,21 @@ def setup(self):
257257
)
258258

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

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

0 commit comments

Comments
 (0)