@@ -127,6 +127,20 @@ def params(self) -> Sequence[openai.types.chat.ChatCompletionToolParam]:
127127 },
128128 },
129129 ),
130+ self ._param (
131+ name = "rename_file" ,
132+ description = "Rename a file" ,
133+ inputs = {
134+ "src_path" : {
135+ "type" : "string" ,
136+ "description" : "Old file path" ,
137+ },
138+ "dst_path" : {
139+ "type" : "string" ,
140+ "description" : "New file path" ,
141+ },
142+ },
143+ ),
130144 ]
131145
132146
@@ -159,29 +173,39 @@ def _on_write_file(self, path: PurePosixPath) -> V:
159173 def _on_delete_file (self , path : PurePosixPath ) -> V :
160174 raise NotImplementedError ()
161175
176+ def _on_rename_file (
177+ self , src_path : PurePosixPath , dst_path : PurePosixPath
178+ ) -> V :
179+ raise NotImplementedError ()
180+
162181 def _on_list_files (self , paths : Sequence [PurePosixPath ]) -> V :
163182 raise NotImplementedError ()
164183
165184 def handle_function (self , function : Any ) -> V :
166- name = function .name
167185 inputs = json .loads (function .arguments )
168186 _logger .info ("Requested function: %s" , function )
169- if name == "read_file" :
170- path = PurePosixPath (inputs ["path" ])
171- return self ._on_read_file (path , self ._toolbox .read_file (path ))
172- elif name == "write_file" :
173- path = PurePosixPath (inputs ["path" ])
174- contents = inputs ["contents" ]
175- self ._toolbox .write_file (path , contents )
176- return self ._on_write_file (path )
177- elif name == "delete_file" :
178- path = PurePosixPath (inputs ["path" ])
179- self ._toolbox .delete_file (path )
180- return self ._on_delete_file (path )
181- else :
182- assert name == "list_files" and not inputs
183- paths = self ._toolbox .list_files ()
184- return self ._on_list_files (paths )
187+ match function .name :
188+ case "read_file" :
189+ path = PurePosixPath (inputs ["path" ])
190+ return self ._on_read_file (path , self ._toolbox .read_file (path ))
191+ case "write_file" :
192+ path = PurePosixPath (inputs ["path" ])
193+ contents = inputs ["contents" ]
194+ self ._toolbox .write_file (path , contents )
195+ return self ._on_write_file (path )
196+ case "delete_file" :
197+ path = PurePosixPath (inputs ["path" ])
198+ self ._toolbox .delete_file (path )
199+ return self ._on_delete_file (path )
200+ case "rename_file" :
201+ src_path = PurePosixPath (inputs ["src_path" ])
202+ dst_path = PurePosixPath (inputs ["dst_path" ])
203+ self ._toolbox .rename_file (src_path , dst_path )
204+ return self ._on_rename_file (src_path , dst_path )
205+ case _ as name :
206+ assert name == "list_files" and not inputs
207+ paths = self ._toolbox .list_files ()
208+ return self ._on_list_files (paths )
185209
186210
187211class _CompletionsBot (Bot ):
@@ -234,6 +258,11 @@ def _on_write_file(self, _path: PurePosixPath) -> None:
234258 def _on_delete_file (self , _path : PurePosixPath ) -> None :
235259 return None
236260
261+ def _on_rename_file (
262+ self , _src_path : PurePosixPath , _dst_path : PurePosixPath
263+ ) -> None :
264+ return None
265+
237266 def _on_list_files (self , paths : Sequence [PurePosixPath ]) -> str :
238267 joined = "\n " .join (f"* { p } " for p in paths )
239268 return f"Here are the available files: { joined } "
@@ -360,5 +389,10 @@ def _on_write_file(self, _path: PurePosixPath) -> _ToolOutput:
360389 def _on_delete_file (self , _path : PurePosixPath ) -> _ToolOutput :
361390 return self ._wrap ("OK" )
362391
392+ def _on_rename_file (
393+ self , _src_path : PurePosixPath , _dst_path : PurePosixPath
394+ ) -> _ToolOutput :
395+ return self ._wrap ("OK" )
396+
363397 def _on_list_files (self , paths : Sequence [PurePosixPath ]) -> _ToolOutput :
364398 return self ._wrap ("\n " .join (str (p ) for p in paths ))
0 commit comments