sergiopaniego HF Staff commited on
Commit
e773eed
ยท
verified ยท
1 Parent(s): b80f0fd

Upload folder using huggingface_hub

Browse files
openenv_repl.egg-info/PKG-INFO ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Metadata-Version: 2.4
2
+ Name: openenv-repl
3
+ Version: 0.1.0
4
+ Summary: Recursive Language Model REPL Environment for OpenEnv
5
+ Requires-Python: >=3.10
6
+ Requires-Dist: openenv-core[core]>=0.2.3
7
+ Requires-Dist: fastapi>=0.115.0
8
+ Requires-Dist: pydantic>=2.0.0
9
+ Requires-Dist: uvicorn>=0.24.0
10
+ Requires-Dist: requests>=2.31.0
11
+ Requires-Dist: smolagents<2,>=1.22.0
12
+ Requires-Dist: huggingface_hub>=0.20.0
13
+ Requires-Dist: gradio>=4.0.0
14
+ Provides-Extra: dev
15
+ Requires-Dist: pytest>=9.0.3; extra == "dev"
16
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
openenv_repl.egg-info/SOURCES.txt ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ README.md
2
+ pyproject.toml
3
+ ./__init__.py
4
+ ./client.py
5
+ ./local.py
6
+ ./models.py
7
+ ./prompts.py
8
+ ./recursive_backends.py
9
+ ./recursive_controller.py
10
+ ./rubrics.py
11
+ ./runner.py
12
+ openenv_repl.egg-info/PKG-INFO
13
+ openenv_repl.egg-info/SOURCES.txt
14
+ openenv_repl.egg-info/dependency_links.txt
15
+ openenv_repl.egg-info/entry_points.txt
16
+ openenv_repl.egg-info/requires.txt
17
+ openenv_repl.egg-info/top_level.txt
18
+ server/__init__.py
19
+ server/app.py
20
+ server/gradio_ui.py
21
+ server/python_executor.py
22
+ server/repl_environment.py
openenv_repl.egg-info/dependency_links.txt ADDED
@@ -0,0 +1 @@
 
 
1
+
openenv_repl.egg-info/entry_points.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [console_scripts]
2
+ server = repl_env.server.app:main
openenv_repl.egg-info/requires.txt ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ openenv-core[core]>=0.2.3
2
+ fastapi>=0.115.0
3
+ pydantic>=2.0.0
4
+ uvicorn>=0.24.0
5
+ requests>=2.31.0
6
+ smolagents<2,>=1.22.0
7
+ huggingface_hub>=0.20.0
8
+ gradio>=4.0.0
9
+
10
+ [dev]
11
+ pytest>=9.0.3
12
+ pytest-cov>=4.0.0
openenv_repl.egg-info/top_level.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ repl_env
server/gradio_ui.py CHANGED
@@ -15,6 +15,58 @@ import gradio as gr
15
  from openenv.core.env_server.types import EnvironmentMetadata
16
 
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  def _code_block(title: str, content: str) -> str:
19
  if not content:
20
  return ""
@@ -38,7 +90,8 @@ def _format_repl_response(data: Dict[str, Any]) -> str:
38
  available_variables = observation.get("available_variables") or []
39
  if available_variables:
40
  sections.append(
41
- "**Available Variables:** " + ", ".join(f"`{name}`" for name in available_variables)
 
42
  )
43
 
44
  if result.get("locals_snapshot"):
@@ -70,7 +123,12 @@ def build_repl_gradio_app(
70
  quick_start_md: str,
71
  ) -> gr.Blocks:
72
  """Build the REPL-specific Gradio tab."""
73
- del action_fields, is_chat_env, metadata, quick_start_md
 
 
 
 
 
74
 
75
  async def reset_repl(
76
  context: str,
@@ -122,14 +180,30 @@ def build_repl_gradio_app(
122
  except Exception as exc:
123
  return f"Error: {exc}"
124
 
 
 
 
125
  with gr.Blocks(title=f"{title} - REPL") as blocks:
126
  gr.Markdown(
127
  "# REPL Control Panel\n\n"
128
  "Load a problem into the REPL, execute Python, and inspect state without "
129
  "leaving the Space."
130
  )
 
 
 
 
 
 
 
 
 
 
 
 
131
  with gr.Row():
132
  with gr.Column(scale=2):
 
133
  context = gr.Textbox(
134
  label="Context",
135
  placeholder="Problem context or source text...",
@@ -191,5 +265,9 @@ def build_repl_gradio_app(
191
  outputs=[session_view, raw_json, state_json, status],
192
  )
193
  state_btn.click(fn=get_state_sync, outputs=[state_json])
 
 
 
 
194
 
195
  return blocks
 
15
  from openenv.core.env_server.types import EnvironmentMetadata
16
 
17
 
18
+ # One-shot example for the "Load example" button: a classic RLM
19
+ # needle-in-a-haystack demo with parallel child LM calls over chunks.
20
+ _EXAMPLE_CONTEXT = """ACME Robotics โ€” Q1 internal changelog, build notes, and incident log.
21
+
22
+ Week 1. Fleet rollout reached 412 units across warehouses A and B. Latency regression on the manipulator firmware was traced back to the new servo driver; hotfix 1.4.2 shipped Wednesday. No customer impact.
23
+
24
+ Week 2. Vision team rotated the training dataset to include low-light scenes. Offline eval improved 3.1% on the occluded-grasping benchmark but regressed 0.8% on the clean-table benchmark. Product signed off on the trade-off.
25
+
26
+ Week 3. Security audit flagged credential handling in the pairing flow. The legacy MQTT broker was retired. Any robot still on firmware < 1.3.0 will refuse to pair after May 1 โ€” document this in the migration note. The activation code is BANANA-747. Do not share externally. Re-keying ceremony for the HSM happens next sprint.
27
+
28
+ Week 4. Onboarding four new SREs. Runbook for the arm-joint recalibration was rewritten from scratch after the Tuesday incident. New runbook lives under ops/arm/joint-recal/v2.md. The Tuesday incident: a collision with a pallet rack during autonomous pickup. Root cause: stale depth-map cache. Mitigation: cache TTL dropped from 5 minutes to 20 seconds.
29
+
30
+ Week 5. Starting the unification work on the control plane. Two clusters are being collapsed into one, with staged traffic shifting. Rollback criteria are defined in the RFC. Early signal looks good: no increase in p99 pick latency. Next milestone: full cutover.
31
+
32
+ Week 6. Offsite in Porto. Platform team proposed a new interface between the planner and the low-level controller. Discussion deferred to the RFC process. Interesting prior art from the MIT paper on whole-body MPC. Follow-up reading list shared in the team channel."""
33
+
34
+ _EXAMPLE_TASK_PROMPT = "Find the activation code hidden somewhere in the changelog."
35
+
36
+ _EXAMPLE_CODE = """chunks = [context[i:i+600] for i in range(0, len(context), 600)]
37
+ prompts = [f"Return only an activation code WORD-NNN if present, else NONE.\\n\\n{c}" for c in chunks]
38
+ answers = llm_query_batched(prompts)
39
+ hit = next((a.strip() for a in answers if "NONE" not in a.upper()), "not found")
40
+ print(f"spawned {len(chunks)} children")
41
+ print(FINAL(hit))"""
42
+
43
+
44
+ _HELPERS_MD = """
45
+ ### REPL helpers
46
+
47
+ These names are injected into the Python namespace once you Reset:
48
+
49
+ - `context` โ€” the string you passed in the *Context* field, available as a variable.
50
+ - `task_prompt` โ€” the string you passed in the *Task Prompt* field.
51
+ - `llm_query(prompt, model=None)` โ€” single direct call to the configured LLM.
52
+ - `llm_query_batched(prompts, model=None)` โ€” fan out N direct LLM calls in parallel.
53
+ - `rlm_query(prompt)` / `rlm_query_batched(prompts)` โ€” each child runs a full recursive REPL loop (deeper RLM pattern).
54
+ - `FINAL(value)` โ€” finalize the episode with `value` as the answer.
55
+ - `FINAL_VAR("name")` โ€” finalize with the value of the named variable.
56
+ - `answer = {"content": ..., "ready": True}` โ€” dict-based finalization.
57
+
58
+ ### Typical flow
59
+
60
+ 1. Open **Optional Model Settings**, paste an HF token, (optionally) set `LLM Model`.
61
+ 2. Write Context + Task Prompt.
62
+ 3. Click **Reset** โ€” this loads your context and wires up the helpers above.
63
+ 4. Write Python in *Python Code* that uses those helpers and ends with `FINAL(...)`.
64
+ 5. Click **Run**. Inspect *Stdout* and *Raw JSON response* (the latter contains child-call metadata for recursive runs).
65
+
66
+ Don't know where to start? Click **Load example** below to pre-fill a working needle-in-a-haystack demo.
67
+ """
68
+
69
+
70
  def _code_block(title: str, content: str) -> str:
71
  if not content:
72
  return ""
 
90
  available_variables = observation.get("available_variables") or []
91
  if available_variables:
92
  sections.append(
93
+ "**Available Variables:** "
94
+ + ", ".join(f"`{name}`" for name in available_variables)
95
  )
96
 
97
  if result.get("locals_snapshot"):
 
123
  quick_start_md: str,
124
  ) -> gr.Blocks:
125
  """Build the REPL-specific Gradio tab."""
126
+ del action_fields, is_chat_env
127
+
128
+ env_description = metadata.description if metadata and metadata.description else ""
129
+ readme_content = (
130
+ metadata.readme_content if metadata and metadata.readme_content else ""
131
+ )
132
 
133
  async def reset_repl(
134
  context: str,
 
180
  except Exception as exc:
181
  return f"Error: {exc}"
182
 
183
+ def load_example():
184
+ return _EXAMPLE_CONTEXT, _EXAMPLE_TASK_PROMPT, _EXAMPLE_CODE
185
+
186
  with gr.Blocks(title=f"{title} - REPL") as blocks:
187
  gr.Markdown(
188
  "# REPL Control Panel\n\n"
189
  "Load a problem into the REPL, execute Python, and inspect state without "
190
  "leaving the Space."
191
  )
192
+
193
+ with gr.Accordion("About this environment", open=True):
194
+ if env_description:
195
+ gr.Markdown(env_description)
196
+ if quick_start_md:
197
+ gr.Markdown(quick_start_md)
198
+ gr.Markdown(_HELPERS_MD)
199
+
200
+ if readme_content:
201
+ with gr.Accordion("Full README", open=False):
202
+ gr.Markdown(readme_content)
203
+
204
  with gr.Row():
205
  with gr.Column(scale=2):
206
+ example_btn = gr.Button("Load example", variant="secondary")
207
  context = gr.Textbox(
208
  label="Context",
209
  placeholder="Problem context or source text...",
 
265
  outputs=[session_view, raw_json, state_json, status],
266
  )
267
  state_btn.click(fn=get_state_sync, outputs=[state_json])
268
+ example_btn.click(
269
+ fn=load_example,
270
+ outputs=[context, task_prompt, code],
271
+ )
272
 
273
  return blocks
server/repl_environment.py CHANGED
@@ -138,7 +138,6 @@ class REPLEnvironment(Environment):
138
  self._executor: Optional[PythonExecutor] = None
139
  self._runtime_controller = None
140
  self._runtime_controller_chat_fn: Optional[Callable[..., str]] = None
141
- self._current_llm_model: Optional[str] = None
142
 
143
  @staticmethod
144
  def _build_hf_chat_fn(
@@ -258,16 +257,11 @@ class REPLEnvironment(Environment):
258
 
259
  # Create or rebuild LLM functions when needed.
260
  # Token resolution: explicit hf_token > HF_TOKEN env var > cached HF login.
261
- # Rebuild when the caller supplies new credentials or switches models,
262
- # so repeated resets with a different llm_model/hf_token take effect.
263
- model_changed = llm_model != self._current_llm_model
264
- token_provided = hf_token is not None
265
- if not self.llm_query_fn or model_changed or token_provided:
266
  effective_token = (
267
  hf_token if hf_token is not None else os.environ.get("HF_TOKEN")
268
  )
269
  self._create_llm_functions(effective_token, llm_model)
270
- self._current_llm_model = llm_model
271
  elif depth_changed and self._runtime_controller is not None:
272
  # Rebuild controller with new depth/iteration config but reuse
273
  # the existing chat_fn โ€” don't require re-providing credentials.
 
138
  self._executor: Optional[PythonExecutor] = None
139
  self._runtime_controller = None
140
  self._runtime_controller_chat_fn: Optional[Callable[..., str]] = None
 
141
 
142
  @staticmethod
143
  def _build_hf_chat_fn(
 
257
 
258
  # Create or rebuild LLM functions when needed.
259
  # Token resolution: explicit hf_token > HF_TOKEN env var > cached HF login.
260
+ if not self.llm_query_fn:
 
 
 
 
261
  effective_token = (
262
  hf_token if hf_token is not None else os.environ.get("HF_TOKEN")
263
  )
264
  self._create_llm_functions(effective_token, llm_model)
 
265
  elif depth_changed and self._runtime_controller is not None:
266
  # Rebuild controller with new depth/iteration config but reuse
267
  # the existing chat_fn โ€” don't require re-providing credentials.