Skip to content

Commit

Permalink
raise RuntimeError rather than Exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Patey committed Jan 13, 2025
1 parent 021a8f4 commit e8c0d2c
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions src/inspect_ai/tool/_tools/_computer/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,38 +38,35 @@ async def _send_cmd(cmdTail: list[str], timeout: int | None = None) -> ToolResul

cmd = ["python3", "-m", "computer_tool.computer_tool", "--action"] + cmdTail

try:
raw_exec_result = await sandbox().exec(cmd, timeout=timeout)
raw_exec_result = await sandbox().exec(cmd, timeout=timeout)

if not raw_exec_result.success:
raise Exception(
f"Failure executing command: ${cmd} {raw_exec_result.stderr}"
)
if not raw_exec_result.success:
raise RuntimeError(
f"Failure executing command: ${cmd} {raw_exec_result.stderr}"
)

result = ToolExecResult(**json.loads(raw_exec_result.stdout))
result = ToolExecResult(**json.loads(raw_exec_result.stdout))

if result.error:
raise ToolError(result.error)
if result.error:
raise ToolError(result.error)

image = (
ContentImage(image=f"data:image/png;base64,{result.base64_image}")
if result.base64_image
else None
)
text = result.output if result.output and len(result.output) > 0 else None
image = (
ContentImage(image=f"data:image/png;base64,{result.base64_image}")
if result.base64_image
else None
)
text = result.output if result.output and len(result.output) > 0 else None

if text is not None and image is not None:
return [ContentText(text=text), image]
if text is not None and image is not None:
return [ContentText(text=text), image]

if text is not None:
return text
if text is not None:
return text

if image is not None:
return [image]
if image is not None:
return [image]

return "OK"
except ToolError:
raise
return "OK"


async def cursor_position(timeout: int | None = None) -> ToolResult:
Expand Down

0 comments on commit e8c0d2c

Please sign in to comment.