(self)
| 93 | return res |
| 94 | |
| 95 | def _update_files(self): |
| 96 | name = self.partial_response_function_call.get("name") |
| 97 | |
| 98 | if name and name != "replace_lines": |
| 99 | raise ValueError(f'Unknown function_call name="{name}", use name="replace_lines"') |
| 100 | |
| 101 | args = self.parse_partial_args() |
| 102 | if not args: |
| 103 | return |
| 104 | |
| 105 | edits = args.get("edits", []) |
| 106 | |
| 107 | edited = set() |
| 108 | for edit in edits: |
| 109 | path = get_arg(edit, "path") |
| 110 | original = get_arg(edit, "original_lines") |
| 111 | updated = get_arg(edit, "updated_lines") |
| 112 | |
| 113 | # gpt-3.5 returns lists even when instructed to return a string! |
| 114 | if self.code_format == "list" or type(original) is list: |
| 115 | original = "\n".join(original) |
| 116 | if self.code_format == "list" or type(updated) is list: |
| 117 | updated = "\n".join(updated) |
| 118 | |
| 119 | if original and not original.endswith("\n"): |
| 120 | original += "\n" |
| 121 | if updated and not updated.endswith("\n"): |
| 122 | updated += "\n" |
| 123 | |
| 124 | full_path = self.allowed_to_edit(path) |
| 125 | if not full_path: |
| 126 | continue |
| 127 | content = self.io.read_text(full_path) |
| 128 | content = do_replace(full_path, content, original, updated) |
| 129 | if content: |
| 130 | self.io.write_text(full_path, content) |
| 131 | edited.add(path) |
| 132 | continue |
| 133 | self.io.tool_error(f"Failed to apply edit to {path}") |
| 134 | |
| 135 | return edited |
| 136 | |
| 137 | |
| 138 | def get_arg(edit, arg): |
nothing calls this directly
no test coverage detected