Skip to content
Merged
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
34 changes: 28 additions & 6 deletions src/git_draft/bots/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ def params(self) -> Sequence[openai.types.chat.ChatCompletionToolParam]:
},
},
),
self._param(
name="delete_file",
description="Delete a file",
inputs={
"path": {
"type": "string",
"description": "Path of the file to be deleted",
},
},
),
]


Expand All @@ -125,12 +135,11 @@ def params(self) -> Sequence[openai.types.chat.ChatCompletionToolParam]:
read the content of the relevant ones, and save the changes you suggest.

You should stop when and ONLY WHEN all the files you need to change have
been updated.

If you stop for any reason before completing your task, explain why by
updating a REASON file before stopping. For example if you are missing some
information or noticed something inconsistent with the instructions, say so
there. DO NOT STOP without updating at least this file.
been updated. If you stop for any reason before completing your task,
explain why by updating a REASON file before stopping. For example if you
are missing some information or noticed something inconsistent with the
instructions, say so there. DO NOT STOP without updating at least this
file.
"""


Expand All @@ -144,6 +153,9 @@ def _on_read_file(self, path: PurePosixPath, contents: str | None) -> V:
def _on_write_file(self, path: PurePosixPath) -> V:
raise NotImplementedError()

def _on_delete_file(self, path: PurePosixPath) -> V:
raise NotImplementedError()

def _on_list_files(self, paths: Sequence[PurePosixPath]) -> V:
raise NotImplementedError()

Expand All @@ -159,6 +171,10 @@ def handle_function(self, function: Any) -> V:
contents = inputs["contents"]
self._toolbox.write_file(path, contents)
return self._on_write_file(path)
elif name == "delete_file":
path = PurePosixPath(inputs["path"])
self._toolbox.delete_file(path)
return self._on_delete_file(path)
else:
assert name == "list_files" and not inputs
paths = self._toolbox.list_files()
Expand Down Expand Up @@ -210,6 +226,9 @@ def _on_read_file(self, path: PurePosixPath, contents: str | None) -> str:
def _on_write_file(self, path: PurePosixPath) -> None:
return None

def _on_delete_file(self, path: PurePosixPath) -> None:
return None

def _on_list_files(self, paths: Sequence[PurePosixPath]) -> str:
joined = "\n".join(f"* {p}" for p in paths)
return f"Here are the available files: {joined}"
Expand Down Expand Up @@ -317,5 +336,8 @@ def _on_read_file(
def _on_write_file(self, path: PurePosixPath) -> _ToolOutput:
return self._wrap("OK")

def _on_delete_file(self, path: PurePosixPath) -> _ToolOutput:
return self._wrap("OK")

def _on_list_files(self, paths: Sequence[PurePosixPath]) -> _ToolOutput:
return self._wrap("\n".join((str(p) for p in paths)))