feat: Use docker api to pull files from container
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from shlex import quote
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from langchain_core.tools import BaseTool, tool
|
||||
@@ -36,11 +35,21 @@ def make_edit_file_tool(sandbox: "DockerSandbox") -> BaseTool:
|
||||
|
||||
Returns a confirmation with the number of lines affected, or an error.
|
||||
"""
|
||||
logger.debug("Editing file inside sandbox: {!r}", path)
|
||||
exit_code, content = sandbox.exec(f"cat -- {quote(path)}")
|
||||
if exit_code != 0:
|
||||
return f"[ERROR reading {path!r} for edit] {content.strip()}"
|
||||
_MAX_EDIT_BYTES = 1_000_000 # 1 MB
|
||||
|
||||
logger.debug("Editing file inside sandbox: {!r}", path)
|
||||
try:
|
||||
data = sandbox.read_file(path)
|
||||
except (FileNotFoundError, IsADirectoryError, RuntimeError) as exc:
|
||||
return f"[ERROR reading {path!r} for edit] {exc}"
|
||||
|
||||
if len(data) > _MAX_EDIT_BYTES:
|
||||
return (
|
||||
f"[ERROR] {path!r} is {len(data)} bytes; edit_file only supports files "
|
||||
f"up to {_MAX_EDIT_BYTES} bytes."
|
||||
)
|
||||
|
||||
content = data.decode("utf-8", errors="replace")
|
||||
count = content.count(old_str)
|
||||
if count == 0:
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user