MCPcopy Index your code
hub / github.com/OpenBMB/ChatDev / rename_path

Function rename_path

functions/function_calling/file.py:601–635  ·  view source on GitHub ↗

Rename files or directories inside the workspace.

(
    src: Annotated[str, ParamMeta(description="Existing workspace-relative path")],
    dst: Annotated[str, ParamMeta(description="New workspace-relative path")],
    *,
    overwrite: Annotated[
        bool,
        ParamMeta(description="Allow replacing an existing destination"),
    ] = False,
    _context: Dict[str, Any] | None = None,
)

Source from the content-addressed store, hash-verified

599
600
601def rename_path(
602 src: Annotated[str, ParamMeta(description="Existing workspace-relative path")],
603 dst: Annotated[str, ParamMeta(description="New workspace-relative path")],
604 *,
605 overwrite: Annotated[
606 bool,
607 ParamMeta(description="Allow replacing an existing destination"),
608 ] = False,
609 _context: Dict[str, Any] | None = None,
610) -> Dict[str, Any]:
611 """Rename files or directories inside the workspace."""
612
613 ctx = FileToolContext(_context)
614 source = ctx.resolve_under_workspace(src)
615 destination = ctx.resolve_under_workspace(dst)
616 _check_attachments_not_modified(src)
617 _check_attachments_not_modified(dst)
618
619 if not source.exists():
620 raise FileNotFoundError(f"Source does not exist: {src}")
621 if source == destination:
622 return {
623 "path": ctx.to_workspace_relative(destination),
624 "operation": "rename",
625 "skipped": True,
626 }
627
628 _clear_destination(destination, overwrite)
629 destination.parent.mkdir(parents=True, exist_ok=True)
630 source.rename(destination)
631 return {
632 "path": ctx.to_workspace_relative(destination),
633 "previous_path": ctx.to_workspace_relative(source),
634 "operation": "rename",
635 }
636
637
638def copy_path(

Callers

nothing calls this directly

Calls 6

to_workspace_relativeMethod · 0.95
ParamMetaClass · 0.90
FileToolContextClass · 0.85
_clear_destinationFunction · 0.85

Tested by

no test coverage detected