Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions retool/retool.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import asyncio
import logging
import re
from typing import Any
Expand All @@ -20,6 +21,7 @@

from verl.tools.base_tool import OpenAIFunctionToolSchema
from verl.tools.sandbox_fusion_tools import SandboxFusionTool
from verl.tools.schemas import ToolResponse
from verl.utils.dataset import RLHFDataset
from verl.utils.reward_score import math_dapo
from verl.utils.rollout_trace import rollout_trace_op
Expand All @@ -33,7 +35,7 @@ def __init__(self, config: dict, tool_schema: OpenAIFunctionToolSchema):
self.code_pattern = re.compile(r"```python(.*?)```", re.DOTALL)

@rollout_trace_op
async def execute(self, instance_id: str, parameters: dict[str, Any], **kwargs) -> tuple[str, float, dict]:
async def execute(self, instance_id: str, parameters: dict[str, Any], **kwargs) -> tuple[ToolResponse, float, dict]:
code = parameters["code"]
matches = self.code_pattern.findall(code)
if matches:
Expand All @@ -54,9 +56,17 @@ async def execute(self, instance_id: str, parameters: dict[str, Any], **kwargs)
if not isinstance(code, str):
code = str(code)

result = await self.execution_pool.execute.remote(self.execute_code, instance_id, code, timeout, language)
# sandbox has no score or metrics, use Nones
return result, None, None
if self.use_ray_execution_pool:
result = await self.execution_pool.execute.remote(self.execute_code, instance_id, code, timeout, language)
else:
async with self._async_semaphore:
result = await asyncio.get_running_loop().run_in_executor(
None, self.execute_code, instance_id, code, timeout, language
)

if isinstance(result, ToolResponse):
return result, None, None
return ToolResponse(text=None if result is None else str(result)), None, None


class CustomRLHFDataset(RLHFDataset):
Expand Down
1 change: 1 addition & 0 deletions retool/sandbox_fusion_tool_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ tools:
default_timeout: 30
default_language: "python"
memory_limit_mb: 1024
use_ray_execution_pool: false
type: native

tool_schema:
Expand Down
Loading