diff --git a/src/git_draft/bots/openai.py b/src/git_draft/bots/openai.py index 4c70f2b..318de13 100644 --- a/src/git_draft/bots/openai.py +++ b/src/git_draft/bots/openai.py @@ -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", + }, + }, + ), ] @@ -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. """ @@ -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() @@ -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() @@ -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}" @@ -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)))