From fb3cc98da5da9ff1f7405613b5eb1cf1928109fd Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 11 Jun 2024 13:29:05 -0700 Subject: [PATCH] cleanup --model-metadata-file --- aider/args.py | 15 ++---------- aider/main.py | 14 +++++------ aider/models.py | 8 ++++--- website/assets/sample.aider.conf.yml | 3 +++ website/docs/aider_conf.md | 3 +++ website/docs/install/optional.md | 21 ----------------- website/docs/llms/warnings.md | 35 ++++++++++++++++++++++++++++ website/docs/options.md | 10 ++++---- 8 files changed, 60 insertions(+), 49 deletions(-) diff --git a/aider/args.py b/aider/args.py index 2c10f8497..4fc956062 100644 --- a/aider/args.py +++ b/aider/args.py @@ -142,21 +142,10 @@ def get_parser(default_config_files, git_root): help="Specify the OpenAI organization ID", ) group.add_argument( - "--model-file", + "--model-metadata-file", metavar="MODEL_FILE", default=None, - help={ - "Specify a file with model definitions (info and cost) to be registered with litellm, json formated", - " {" - " \"gpt-4\": {", - " \"max_tokens\": 8192,", - " \"input_cost_per_token\": 0.00003,", - " \"output_cost_per_token\": 0.00006,", - " \"litellm_provider\": \"openai\",", - " \"mode\": \"chat\"", - " },", - " }" - } + help="Specify a file with context window and costs for unknown models", ) group.add_argument( "--edit-format", diff --git a/aider/main.py b/aider/main.py index 2447efe8e..79c1511d8 100644 --- a/aider/main.py +++ b/aider/main.py @@ -341,17 +341,17 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F model_def_files.append(Path.home() / model_def_fname) # homedir if git_root: model_def_files.append(Path(git_root) / model_def_fname) # git root - if args.model_file: - model_def_files.append(args.model_file) + if args.model_metadata_file: + model_def_files.append(args.model_metadata_file) model_def_files.append(model_def_fname.resolve()) model_def_files = list(map(str, model_def_files)) model_def_files = list(dict.fromkeys(model_def_files)) try: - model_files_loaded=models.register_models(model_def_files) - if len(model_files_loaded) > 0: - io.tool_output(f"Loaded {len(model_files_loaded)} model file(s)") - for model_file in model_files_loaded: - io.tool_output(f" - {model_file}") + model_metadata_files_loaded = models.register_models(model_def_files) + if len(model_metadata_files_loaded) > 0: + io.tool_output(f"Loaded {len(model_metadata_files_loaded)} model file(s)") + for model_metadata_file in model_metadata_files_loaded: + io.tool_output(f" - {model_metadata_file}") except Exception as e: io.tool_error(f"Error loading model info/cost: {e}") return 1 diff --git a/aider/models.py b/aider/models.py index 18e03eb60..f51b38bc4 100644 --- a/aider/models.py +++ b/aider/models.py @@ -426,12 +426,13 @@ class Model: return res + def register_models(model_def_fnames): - model_files_loaded = [] + model_metadata_files_loaded = [] for model_def_fname in model_def_fnames: if not os.path.exists(model_def_fname): continue - model_files_loaded.append(model_def_fname) + model_metadata_files_loaded.append(model_def_fname) try: with open(model_def_fname, "r") as model_def_file: model_def = json.load(model_def_file) @@ -440,7 +441,8 @@ def register_models(model_def_fnames): litellm.register_model(model_def) - return model_files_loaded + return model_metadata_files_loaded + def validate_variables(vars): missing = [] diff --git a/website/assets/sample.aider.conf.yml b/website/assets/sample.aider.conf.yml index adf16cd0b..a4ecb0928 100644 --- a/website/assets/sample.aider.conf.yml +++ b/website/assets/sample.aider.conf.yml @@ -63,6 +63,9 @@ ## Specify the OpenAI organization ID #openai-organization-id: +## Specify a file with context window and costs for unknown models +#model-metadata-file: + ## Specify what edit format the LLM should use (default depends on model) #edit-format: diff --git a/website/docs/aider_conf.md b/website/docs/aider_conf.md index 98f1e683f..344ebc534 100644 --- a/website/docs/aider_conf.md +++ b/website/docs/aider_conf.md @@ -89,6 +89,9 @@ cog.outl("```") ## Specify the OpenAI organization ID #openai-organization-id: +## Specify a file with context window and costs for unknown models +#model-metadata-file: + ## Specify what edit format the LLM should use (default depends on model) #edit-format: diff --git a/website/docs/install/optional.md b/website/docs/install/optional.md index acf043209..846642d93 100644 --- a/website/docs/install/optional.md +++ b/website/docs/install/optional.md @@ -26,27 +26,6 @@ Put a line in it like this to specify your api key: openai-api-key: sk-... ``` -## Registering Models not in litellm - -You can register model info and costs with litellm by adding one or more of the following files -* {HomeDir}/.aider.models.json -* {GitRoot}/.aider.models.json -* {CWD}/.aider.models.json -* or via the command line argument `model-file` -If the files above exists, they will be loaded in that order. Files loaded last will take priority. -The json file should be formated as follows -``` -{ - "gpt-4": { - "max_tokens": 8192, - "input_cost_per_token": 0.00003, - "output_cost_per_token": 0.00006, - "litellm_provider": "openai", - "mode": "chat", - }, -} -``` -see [litellm's model definitions](https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json) for examples ## Enable Playwright diff --git a/website/docs/llms/warnings.md b/website/docs/llms/warnings.md index 01fe3ed49..0144c5e76 100644 --- a/website/docs/llms/warnings.md +++ b/website/docs/llms/warnings.md @@ -6,3 +6,38 @@ nav_order: 900 # Model warnings {% include model-warnings.md %} + + +## Specifying context window size and token costs + +You can register context window limits and costs for models that aren't known +to aider. Create a `.aider.models.json` file in one of these locations: + +- Your home directory. +- The root if your git repo. +- The current directory where you launch aider. +- Or specify a specific file with the `--model-metadata-file ` switch. + + +If the files above exist, they will be loaded in that order. +Files loaded last will take priority. + +The json file should be a dictionary with an entry for each model, as follows: + +``` +{ + "gpt-4": { + "max_tokens": 4096, + "max_input_tokens": 8192, + "max_output_tokens": 4096, + "input_cost_per_token": 0.00003, + "output_cost_per_token": 0.00006, + "litellm_provider": "openai", + "mode": "chat", + "supports_function_calling": true + } +} +``` + +See +[litellm's model_prices_and_context_window.json file](https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json) for more examples. diff --git a/website/docs/options.md b/website/docs/options.md index 4482e1cb4..2183782d5 100644 --- a/website/docs/options.md +++ b/website/docs/options.md @@ -19,7 +19,7 @@ usage: aider [-h] [--vim] [--openai-api-key] [--anthropic-api-key] [--35turbo] [--models] [--openai-api-base] [--openai-api-type] [--openai-api-version] [--openai-api-deployment-id] [--openai-organization-id] - [--edit-format] [--weak-model] + [--model-metadata-file] [--edit-format] [--weak-model] [--show-model-warnings | --no-show-model-warnings] [--map-tokens] [--max-chat-history-tokens] [--env-file] [--input-history-file] [--chat-history-file] @@ -108,10 +108,6 @@ Aliases: List known models which match the (partial) MODEL name Environment variable: `AIDER_MODELS` -### `--model-file FILE` -Specify a file with model definitions (info and cost) to be registered with litellm, json formated. See [Registering Models not in litellm](install/optional.md#registering_models_not_in_litellm) for the format -Environment variable: `AIDER_MODEL_FILE` - ### `--openai-api-base OPENAI_API_BASE` Specify the api base url Environment variable: `OPENAI_API_BASE` @@ -132,6 +128,10 @@ Environment variable: `OPENAI_API_DEPLOYMENT_ID` Specify the OpenAI organization ID Environment variable: `OPENAI_ORGANIZATION_ID` +### `--model-metadata-file MODEL_FILE` +Specify a file with context window and costs for unknown models +Environment variable: `AIDER_MODEL_METADATA_FILE` + ### `--edit-format EDIT_FORMAT` Specify what edit format the LLM should use (default depends on model) Environment variable: `AIDER_EDIT_FORMAT`