mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 14:25:00 +00:00
Refactor create
method to use dynamic coder selection based on edit_format
This commit is contained in:
parent
563729ad94
commit
4d4bfba965
1 changed files with 8 additions and 22 deletions
|
@ -82,13 +82,7 @@ class Coder:
|
||||||
summarize_from_coder=True,
|
summarize_from_coder=True,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
from . import (
|
import aider.coders as coders
|
||||||
EditBlockCoder,
|
|
||||||
EditBlockFencedCoder,
|
|
||||||
HelpCoder,
|
|
||||||
UnifiedDiffCoder,
|
|
||||||
WholeFileCoder,
|
|
||||||
)
|
|
||||||
|
|
||||||
if not main_model:
|
if not main_model:
|
||||||
if from_coder:
|
if from_coder:
|
||||||
|
@ -129,22 +123,14 @@ class Coder:
|
||||||
|
|
||||||
kwargs = use_kwargs
|
kwargs = use_kwargs
|
||||||
|
|
||||||
if edit_format == "diff":
|
for coder_class in coders.__all__:
|
||||||
res = EditBlockCoder(main_model, io, **kwargs)
|
coder = getattr(coders, coder_class)
|
||||||
elif edit_format == "diff-fenced":
|
if hasattr(coder, 'edit_format') and coder.edit_format == edit_format:
|
||||||
res = EditBlockFencedCoder(main_model, io, **kwargs)
|
res = coder(main_model, io, **kwargs)
|
||||||
elif edit_format == "whole":
|
res.original_kwargs = dict(kwargs)
|
||||||
res = WholeFileCoder(main_model, io, **kwargs)
|
return res
|
||||||
elif edit_format == "udiff":
|
|
||||||
res = UnifiedDiffCoder(main_model, io, **kwargs)
|
|
||||||
elif edit_format == "help":
|
|
||||||
res = HelpCoder(main_model, io, **kwargs)
|
|
||||||
else:
|
|
||||||
raise ValueError(f"Unknown edit format {edit_format}")
|
|
||||||
|
|
||||||
res.original_kwargs = dict(kwargs)
|
raise ValueError(f"Unknown edit format {edit_format}")
|
||||||
|
|
||||||
return res
|
|
||||||
|
|
||||||
def clone(self, **kwargs):
|
def clone(self, **kwargs):
|
||||||
return Coder.create(from_coder=self, **kwargs)
|
return Coder.create(from_coder=self, **kwargs)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue