@@ -28,6 +28,7 @@ class LLMProxyHandler(BaseHTTPRequestHandler):
2828 lm_handler_address : tuple [str , int ] | None = None
2929 pending_calls : list [RLMChatCompletion ] = []
3030 lock : threading .Lock = threading .Lock ()
31+ depth : int = 1
3132
3233 def log_message (self , * args ):
3334 pass
@@ -55,7 +56,7 @@ def _handle_single(self, body: dict) -> dict:
5556 if not self .lm_handler_address :
5657 return {"error" : "No LM handler configured" }
5758
58- request = LMRequest (prompt = body .get ("prompt" ), model = body .get ("model" ))
59+ request = LMRequest (prompt = body .get ("prompt" ), model = body .get ("model" ), depth = self . depth )
5960 response = send_lm_request (self .lm_handler_address , request )
6061
6162 if not response .success :
@@ -72,7 +73,7 @@ def _handle_batched(self, body: dict) -> dict:
7273
7374 prompts = body .get ("prompts" , [])
7475 responses = send_lm_request_batched (
75- self .lm_handler_address , prompts , model = body .get ("model" )
76+ self .lm_handler_address , prompts , model = body .get ("model" ), depth = self . depth
7677 )
7778
7879 results = []
@@ -87,7 +88,7 @@ def _handle_batched(self, body: dict) -> dict:
8788 return {"responses" : results }
8889
8990
90- def _build_exec_script (code : str , proxy_port : int ) -> str :
91+ def _build_exec_script (code : str , proxy_port : int , depth : int = 1 ) -> str :
9192 """Build execution script for the container."""
9293 code_b64 = base64 .b64encode (code .encode ()).decode ()
9394
@@ -104,15 +105,15 @@ def _build_exec_script(code: str, proxy_port: int) -> str:
104105
105106def llm_query(prompt, model=None):
106107 try:
107- r = requests.post(f"{{PROXY}}/llm_query", json={{"prompt": prompt, "model": model}}, timeout=300)
108+ r = requests.post(f"{{PROXY}}/llm_query", json={{"prompt": prompt, "model": model, "depth": { depth } }}, timeout=300)
108109 d = r.json()
109110 return d.get("response") or f"Error: {{d.get('error')}}"
110111 except Exception as e:
111112 return f"Error: {{e}}"
112113
113114def llm_query_batched(prompts, model=None):
114115 try:
115- r = requests.post(f"{{PROXY}}/llm_query_batched", json={{"prompts": prompts, "model": model}}, timeout=300)
116+ r = requests.post(f"{{PROXY}}/llm_query_batched", json={{"prompts": prompts, "model": model, "depth": { depth } }}, timeout=300)
116117 d = r.json()
117118 return d.get("responses") or [f"Error: {{d.get('error')}}"] * len(prompts)
118119 except Exception as e:
@@ -181,13 +182,14 @@ def __init__(
181182 context_payload : dict | list | str | None = None ,
182183 setup_code : str | None = None ,
183184 persistent : bool = False ,
185+ depth : int = 1 ,
184186 ** kwargs ,
185187 ):
186188 if persistent :
187189 raise NotImplementedError (
188190 "Persistent REPLs are currently not supported for environment: DockerREPL"
189191 )
190- super ().__init__ (persistent = persistent , ** kwargs )
192+ super ().__init__ (persistent = persistent , depth = depth , ** kwargs )
191193
192194 self .image = image
193195 self .lm_handler_address = lm_handler_address
@@ -216,6 +218,7 @@ def setup(self):
216218 "lm_handler_address" : self .lm_handler_address ,
217219 "pending_calls" : self .pending_calls ,
218220 "lock" : self ._calls_lock ,
221+ "depth" : self .depth ,
219222 },
220223 )
221224 self .proxy_server = HTTPServer (("127.0.0.1" , 0 ), handler )
@@ -266,7 +269,7 @@ def execute_code(self, code: str) -> REPLResult:
266269 with self ._calls_lock :
267270 self .pending_calls .clear ()
268271
269- script = _build_exec_script (code , self .proxy_port )
272+ script = _build_exec_script (code , self .proxy_port , self . depth )
270273 result = subprocess .run (
271274 ["docker" , "exec" , self .container_id , "python" , "-c" , script ],
272275 capture_output = True ,
0 commit comments