Skip to content

Commit

Permalink
Replace file editor with openhands-aci (#4782)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhoangt authored Nov 12, 2024
1 parent 32fdcd5 commit d9c5f11
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 648 deletions.
62 changes: 5 additions & 57 deletions openhands/runtime/plugins/agent_skills/file_editor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,8 @@
"""This file contains a global singleton of the `EditTool` class as well as raw functions that expose its __call__."""

from .base import CLIResult, ToolError, ToolResult
from .impl import Command, EditTool

_GLOBAL_EDITOR = EditTool()


def _make_api_tool_result(
result: ToolResult,
) -> str:
"""Convert an agent ToolResult to an API ToolResultBlockParam."""
tool_result_content: str = ''
is_error = False
if result.error:
is_error = True
tool_result_content = _maybe_prepend_system_tool_result(result, result.error)
else:
assert result.output, 'Expecting output in file_editor'
tool_result_content = _maybe_prepend_system_tool_result(result, result.output)
assert (
not result.base64_image
), 'Not expecting base64_image as output in file_editor'
if is_error:
return f'ERROR:\n{tool_result_content}'
else:
return tool_result_content


def _maybe_prepend_system_tool_result(result: ToolResult, result_text: str) -> str:
if result.system:
result_text = f'<system>{result.system}</system>\n{result_text}'
return result_text


def file_editor(
command: Command,
path: str,
file_text: str | None = None,
view_range: list[int] | None = None,
old_str: str | None = None,
new_str: str | None = None,
insert_line: int | None = None,
) -> str:
try:
result: CLIResult = _GLOBAL_EDITOR(
command=command,
path=path,
file_text=file_text,
view_range=view_range,
old_str=old_str,
new_str=new_str,
insert_line=insert_line,
)
except ToolError as e:
return _make_api_tool_result(ToolResult(error=e.message))
return _make_api_tool_result(result)
"""This file imports a global singleton of the `EditTool` class as well as raw functions that expose
its __call__.
The implementation of the `EditTool` class can be found at: https://github.com/All-Hands-AI/openhands-aci/.
"""

from openhands_aci.editor import file_editor

__all__ = ['file_editor']
50 changes: 0 additions & 50 deletions openhands/runtime/plugins/agent_skills/file_editor/base.py

This file was deleted.

279 changes: 0 additions & 279 deletions openhands/runtime/plugins/agent_skills/file_editor/impl.py

This file was deleted.

Loading

0 comments on commit d9c5f11

Please sign in to comment.