| 123 | |
| 124 | @classmethod |
| 125 | def create( |
| 126 | self, |
| 127 | main_model=None, |
| 128 | edit_format=None, |
| 129 | io=None, |
| 130 | from_coder=None, |
| 131 | summarize_from_coder=True, |
| 132 | **kwargs, |
| 133 | ): |
| 134 | import aider.coders as coders |
| 135 | |
| 136 | if not main_model: |
| 137 | if from_coder: |
| 138 | main_model = from_coder.main_model |
| 139 | else: |
| 140 | main_model = models.Model(models.DEFAULT_MODEL_NAME) |
| 141 | |
| 142 | if edit_format == "code": |
| 143 | edit_format = None |
| 144 | if edit_format is None: |
| 145 | if from_coder: |
| 146 | edit_format = from_coder.edit_format |
| 147 | else: |
| 148 | edit_format = main_model.edit_format |
| 149 | |
| 150 | if not io and from_coder: |
| 151 | io = from_coder.io |
| 152 | |
| 153 | if from_coder: |
| 154 | use_kwargs = dict(from_coder.original_kwargs) # copy orig kwargs |
| 155 | |
| 156 | # If the edit format changes, we can't leave old ASSISTANT |
| 157 | # messages in the chat history. The old edit format will |
| 158 | # confused the new LLM. It may try and imitate it, disobeying |
| 159 | # the system prompt. |
| 160 | done_messages = from_coder.done_messages |
| 161 | if edit_format != from_coder.edit_format and done_messages and summarize_from_coder: |
| 162 | try: |
| 163 | done_messages = from_coder.summarizer.summarize_all(done_messages) |
| 164 | except ValueError: |
| 165 | # If summarization fails, keep the original messages and warn the user |
| 166 | io.tool_warning( |
| 167 | "Chat history summarization failed, continuing with full history" |
| 168 | ) |
| 169 | |
| 170 | # Bring along context from the old Coder |
| 171 | update = dict( |
| 172 | fnames=list(from_coder.abs_fnames), |
| 173 | read_only_fnames=list(from_coder.abs_read_only_fnames), # Copy read-only files |
| 174 | done_messages=done_messages, |
| 175 | cur_messages=from_coder.cur_messages, |
| 176 | aider_commit_hashes=from_coder.aider_commit_hashes, |
| 177 | commands=from_coder.commands.clone(), |
| 178 | total_cost=from_coder.total_cost, |
| 179 | ignore_mentions=from_coder.ignore_mentions, |
| 180 | total_tokens_sent=from_coder.total_tokens_sent, |
| 181 | total_tokens_received=from_coder.total_tokens_received, |
| 182 | file_watcher=from_coder.file_watcher, |