refactor: move model shortcut args to deprecated module with warnings

This commit is contained in:
Paul Gauthier (aider) 2025-03-08 13:38:06 -08:00
parent 6bf683409f
commit fe60832492
3 changed files with 133 additions and 92 deletions

View file

@ -12,6 +12,7 @@ from aider.args_formatter import (
MarkdownHelpFormatter,
YamlHelpFormatter,
)
from aider.deprecated import add_deprecated_model_args
from .dump import dump # noqa: F401
@ -38,98 +39,9 @@ def get_parser(default_config_files, git_root):
default=None,
help="Specify the model to use for the main chat",
)
opus_model = "claude-3-opus-20240229"
group.add_argument(
"--opus",
action="store_const",
dest="model",
const=opus_model,
help=f"Use {opus_model} model for the main chat",
)
sonnet_model = "anthropic/claude-3-7-sonnet-20250219"
group.add_argument(
"--sonnet",
action="store_const",
dest="model",
const=sonnet_model,
help=f"Use {sonnet_model} model for the main chat",
)
haiku_model = "claude-3-5-haiku-20241022"
group.add_argument(
"--haiku",
action="store_const",
dest="model",
const=haiku_model,
help=f"Use {haiku_model} model for the main chat",
)
gpt_4_model = "gpt-4-0613"
group.add_argument(
"--4",
"-4",
action="store_const",
dest="model",
const=gpt_4_model,
help=f"Use {gpt_4_model} model for the main chat",
)
gpt_4o_model = "gpt-4o"
group.add_argument(
"--4o",
action="store_const",
dest="model",
const=gpt_4o_model,
help=f"Use {gpt_4o_model} model for the main chat",
)
gpt_4o_mini_model = "gpt-4o-mini"
group.add_argument(
"--mini",
action="store_const",
dest="model",
const=gpt_4o_mini_model,
help=f"Use {gpt_4o_mini_model} model for the main chat",
)
gpt_4_turbo_model = "gpt-4-1106-preview"
group.add_argument(
"--4-turbo",
action="store_const",
dest="model",
const=gpt_4_turbo_model,
help=f"Use {gpt_4_turbo_model} model for the main chat",
)
gpt_3_model_name = "gpt-3.5-turbo"
group.add_argument(
"--35turbo",
"--35-turbo",
"--3",
"-3",
action="store_const",
dest="model",
const=gpt_3_model_name,
help=f"Use {gpt_3_model_name} model for the main chat",
)
deepseek_model = "deepseek/deepseek-chat"
group.add_argument(
"--deepseek",
action="store_const",
dest="model",
const=deepseek_model,
help=f"Use {deepseek_model} model for the main chat",
)
o1_mini_model = "o1-mini"
group.add_argument(
"--o1-mini",
action="store_const",
dest="model",
const=o1_mini_model,
help=f"Use {o1_mini_model} model for the main chat",
)
o1_preview_model = "o1-preview"
group.add_argument(
"--o1-preview",
action="store_const",
dest="model",
const=o1_preview_model,
help=f"Use {o1_preview_model} model for the main chat",
)
# Add deprecated model shortcut arguments
add_deprecated_model_args(parser, group)
##########
group = parser.add_argument_group("API Keys and settings")

125
aider/deprecated.py Normal file
View file

@ -0,0 +1,125 @@
def add_deprecated_model_args(parser, group):
"""Add deprecated model shortcut arguments to the argparse parser."""
opus_model = "claude-3-opus-20240229"
group.add_argument(
"--opus",
action="store_true",
help=f"Use {opus_model} model for the main chat (deprecated, use --model)",
default=False,
)
sonnet_model = "anthropic/claude-3-7-sonnet-20250219"
group.add_argument(
"--sonnet",
action="store_true",
help=f"Use {sonnet_model} model for the main chat (deprecated, use --model)",
default=False,
)
haiku_model = "claude-3-5-haiku-20241022"
group.add_argument(
"--haiku",
action="store_true",
help=f"Use {haiku_model} model for the main chat (deprecated, use --model)",
default=False,
)
gpt_4_model = "gpt-4-0613"
group.add_argument(
"--4",
"-4",
action="store_true",
help=f"Use {gpt_4_model} model for the main chat (deprecated, use --model)",
default=False,
)
gpt_4o_model = "gpt-4o"
group.add_argument(
"--4o",
action="store_true",
help=f"Use {gpt_4o_model} model for the main chat (deprecated, use --model)",
default=False,
)
gpt_4o_mini_model = "gpt-4o-mini"
group.add_argument(
"--mini",
action="store_true",
help=f"Use {gpt_4o_mini_model} model for the main chat (deprecated, use --model)",
default=False,
)
gpt_4_turbo_model = "gpt-4-1106-preview"
group.add_argument(
"--4-turbo",
action="store_true",
help=f"Use {gpt_4_turbo_model} model for the main chat (deprecated, use --model)",
default=False,
)
gpt_3_model_name = "gpt-3.5-turbo"
group.add_argument(
"--35turbo",
"--35-turbo",
"--3",
"-3",
action="store_true",
help=f"Use {gpt_3_model_name} model for the main chat (deprecated, use --model)",
default=False,
)
deepseek_model = "deepseek/deepseek-chat"
group.add_argument(
"--deepseek",
action="store_true",
help=f"Use {deepseek_model} model for the main chat (deprecated, use --model)",
default=False,
)
o1_mini_model = "o1-mini"
group.add_argument(
"--o1-mini",
action="store_true",
help=f"Use {o1_mini_model} model for the main chat (deprecated, use --model)",
default=False,
)
o1_preview_model = "o1-preview"
group.add_argument(
"--o1-preview",
action="store_true",
help=f"Use {o1_preview_model} model for the main chat (deprecated, use --model)",
default=False,
)
def handle_deprecated_model_args(args, io):
"""Handle deprecated model shortcut arguments and provide appropriate warnings."""
# Define model mapping
model_map = {
"opus": "claude-3-opus-20240229",
"sonnet": "anthropic/claude-3-7-sonnet-20250219",
"haiku": "claude-3-5-haiku-20241022",
"4": "gpt-4-0613",
"4o": "gpt-4o",
"mini": "gpt-4o-mini",
"4_turbo": "gpt-4-1106-preview",
"35turbo": "gpt-3.5-turbo",
"deepseek": "deepseek/deepseek-chat",
"o1_mini": "o1-mini",
"o1_preview": "o1-preview",
}
# Check if any deprecated args are used
for arg_name, model_name in model_map.items():
arg_name_clean = arg_name.replace("-", "_")
if hasattr(args, arg_name_clean) and getattr(args, arg_name_clean):
# Find preferred name to display in warning
from aider.models import MODEL_ALIASES
display_name = model_name
# Check if there's a shorter alias for this model
for alias, full_name in MODEL_ALIASES.items():
if full_name == model_name:
display_name = alias
break
# Show the warning
io.tool_warning(
f"The --{arg_name.replace('_', '-')} flag is deprecated and will be removed in a future version. "
f"Please use --model {display_name} instead."
)
# Set the model
args.model = model_name
break

View file

@ -24,6 +24,7 @@ from aider.coders import Coder
from aider.coders.base_coder import UnknownEditFormat
from aider.commands import Commands, SwitchCoder
from aider.copypaste import ClipboardWatcher
from aider.deprecated import handle_deprecated_model_args
from aider.format_settings import format_settings, scrub_sensitive_info
from aider.history import ChatSummary
from aider.io import InputOutput
@ -588,6 +589,9 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
if args.openai_api_key:
os.environ["OPENAI_API_KEY"] = args.openai_api_key
# Handle deprecated model shortcut args
handle_deprecated_model_args(args, io)
if args.openai_api_base:
os.environ["OPENAI_API_BASE"] = args.openai_api_base
if args.openai_api_version: