Skip to content

Commit 9fc2568

Browse files
committed
refactor packages into constants
1 parent 140bde9 commit 9fc2568

5 files changed

Lines changed: 50 additions & 34 deletions

File tree

‎AGENTS.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ uv pip install -e .
1818

1919
# For Modal sandbox support
2020
uv pip install -e ".[modal]"
21+
22+
# For Prime sandbox support
23+
uv pip install -e ".[prime]"
2124
```
2225

2326
## General Guidelines

‎rlm/constants/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Constants module
2+

‎rlm/constants/repl.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Default packages for isolated REPL environments (Modal, Prime, etc.)
2+
3+
APT_PACKAGES = [
4+
"build-essential",
5+
"git",
6+
"curl",
7+
"wget",
8+
"libopenblas-dev",
9+
"liblapack-dev",
10+
]
11+
12+
PIP_PACKAGES = [
13+
# Data science essentials
14+
"numpy>=1.26.0",
15+
"pandas>=2.1.0",
16+
"scipy>=1.11.0",
17+
# Math & symbolic computation
18+
"sympy>=1.12",
19+
# HTTP & APIs
20+
"requests>=2.31.0",
21+
"httpx>=0.25.0",
22+
"flask>=3.0.0",
23+
# Data formats
24+
"pyyaml>=6.0",
25+
"toml>=0.10.2",
26+
# Utilities
27+
"tqdm>=4.66.0",
28+
"python-dateutil>=2.8.2",
29+
"regex>=2023.0.0",
30+
# For state serialization
31+
"dill>=0.3.7",
32+
]

‎rlm/environments/modal_repl.py‎

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import modal
88
import requests
99

10+
from rlm.constants.repl import APT_PACKAGES, PIP_PACKAGES
1011
from rlm.core.comms_utils import LMRequest, send_lm_request, send_lm_request_batched
1112
from rlm.core.types import REPLResult, RLMChatCompletion
1213
from rlm.environments.base_env import IsolatedEnv
@@ -23,35 +24,8 @@ def get_default_image() -> modal.Image:
2324
"""
2425
return (
2526
modal.Image.debian_slim(python_version="3.11")
26-
.apt_install(
27-
"build-essential",
28-
"git",
29-
"curl",
30-
"wget",
31-
"libopenblas-dev",
32-
"liblapack-dev",
33-
)
34-
.pip_install(
35-
# Data science essentials
36-
"numpy>=1.26.0",
37-
"pandas>=2.1.0",
38-
"scipy>=1.11.0",
39-
# Math & symbolic computation
40-
"sympy>=1.12",
41-
# HTTP & APIs
42-
"requests>=2.31.0",
43-
"httpx>=0.25.0",
44-
"flask>=3.0.0",
45-
# Data formats
46-
"pyyaml>=6.0",
47-
"toml>=0.10.2",
48-
# Utilities
49-
"tqdm>=4.66.0",
50-
"python-dateutil>=2.8.2",
51-
"regex>=2023.0.0",
52-
# For state serialization
53-
"dill>=0.3.7",
54-
)
27+
.apt_install(*APT_PACKAGES)
28+
.pip_install(*PIP_PACKAGES)
5529
)
5630

5731

‎rlm/environments/prime_repl.py‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
SandboxClient,
2121
)
2222

23+
from rlm.constants.repl import APT_PACKAGES, PIP_PACKAGES
2324
from rlm.core.comms_utils import LMRequest, send_lm_request, send_lm_request_batched
2425
from rlm.core.types import REPLResult, RLMChatCompletion
2526
from rlm.environments.base_env import IsolatedEnv
@@ -328,11 +329,13 @@ def setup(self):
328329
# Wait for sandbox to be ready
329330
self.client.wait_for_creation(self.sandbox_id, max_attempts=self.timeout_minutes * 60)
330331

331-
# Install dependencies for the broker
332-
self.client.execute_command(
333-
self.sandbox_id,
334-
"pip install flask requests dill",
335-
)
332+
# Install apt dependencies
333+
apt_cmd = "apt-get update && apt-get install -y " + " ".join(APT_PACKAGES)
334+
self.client.execute_command(self.sandbox_id, apt_cmd)
335+
336+
# Install pip dependencies
337+
pip_cmd = "pip install " + " ".join(f'"{pkg}"' for pkg in PIP_PACKAGES)
338+
self.client.execute_command(self.sandbox_id, pip_cmd)
336339

337340
# Write the broker script to the sandbox.
338341
# Unlike Modal's sandbox.exec() which accepts separate args, Prime's
@@ -410,6 +413,7 @@ def _poll_broker(self):
410413
# Get pending requests
411414
resp = requests.get(
412415
f"{self.broker_url}/pending",
416+
timeout=10,
413417
)
414418
pending = resp.json().get("pending", [])
415419

@@ -424,6 +428,7 @@ def _poll_broker(self):
424428
requests.post(
425429
f"{self.broker_url}/respond",
426430
json={"id": request_id, "response": response},
431+
timeout=10,
427432
)
428433

429434
except requests.exceptions.RequestException:

0 commit comments

Comments
 (0)