Loading model file throws error
Issue
I am trying to use a model file to quiet down warning messages according to https://aider.chat/docs/config/adv-model-settings.html. My model file is:
{
"ollama/deepseek-coder-v2": {
"max_tokens": 4096,
"max_input_tokens": 32000,
"max_output_tokens": 4096,
"input_cost_per_token": 0.0,
"output_cost_per_token": 0.0,
"litellm_provider": "ollama",
"mode": "chat"
}
}
and I saved it in .aider.model.metadata.json at the base of my working directory but it wasn't used automatically. I pointed to it with aider --model ollama/deepseek-coder-v2 --edit-format diff --model-settings-file .aider.model.metadata.json. Only then did it try reading the file but shows an error.
aider --model ollama/deepseek-coder-v2 --edit-format diff --model-settings-file .aider.model.metadata.json
Error loading aider model settings: Error loading model settings from .aider.model.metadata.json:
aider.models.ModelSettings() argument after ** must be a mapping, not str
Model ollama/deepseek-coder-v2: Unknown context window size and costs, using sane defaults.
For more info, see: https://aider.chat/docs/llms/warnings.html
Version and model info
Aider v0.42.0 Model: ollama/deepseek-coder-v2 with diff edit format Git repo: .git with 1 files Repo-map: disabled VSCode terminal detected, pretty output has been disabled. Use /help to see in-chat commands, run with --help to see cmd line args
I had the same problem, until I realized I had inadvertently created a ".aider.model.metadata.yml" file and stored the json code there. Doh! Once I created a ".aider.model.metadata.json" file with the proper code it worked flawlessly. The file is stored in my working directory.
I checked to ensure it was .json and deleted and remade the file copying the name straight from aider docs so I didn't get it wrong. I upgraded aider and it now shows that it checks my .env file as it prints that it sees and has Loaded 1 model metadata file(s) but it still has the same error:
PS C:\Users\jason\Coding\family_app\famile\famile_us> aider --model ollama/deepseek-coder-v2 --edit-format diff --model-settings-file .aider.model.metadata.json
Loaded C:\Users\jason\Coding\family_app\famile\famile_us\.env
Error loading aider model settings: Error loading model settings from C:\Users\jason\Coding\family_app\famile\famile_us\.aider.model.metadata.json: aider.models.ModelSettings()
argument after ** must be a mapping, not str
Loaded 1 model metadata file(s)
- C:\Users\jason\Coding\family_app\famile\famile_us\.aider.model.metadata.json
Aider v0.43.0
Model: ollama/deepseek-coder-v2 with diff edit format
Git repo: .git with 5 files
Repo-map: disabled
VSCode terminal detected, pretty output has been disabled.
Use /help <question> to ask for help, run with --help to see cmd line args
So, it checks my .env file and finds:
## Ollama
OLLAMA_API_BASE=http://127.0.0.1:11434
which loads. Then it checks the configuration file at C:\Users\jason\Coding\family_app\famile\famile_us\.aider.model.metadata.json which is at the base of my working directory but returns the exception:
Error loading aider model settings: Error loading model settings from
C:\Users\jason\Coding\family_app\famile\famile_us\.aider.model.metadata.json: aider.models.ModelSettings()
checking aider.models for the ModelSettings() class I found:
def register_models(model_settings_fnames):
files_loaded = []
for model_settings_fname in model_settings_fnames:
if not os.path.exists(model_settings_fname):
continue
try:
with open(model_settings_fname, "r") as model_settings_file:
model_settings_list = yaml.safe_load(model_settings_file)
for model_settings_dict in model_settings_list:
model_settings = ModelSettings(**model_settings_dict)
existing_model_settings = next(
(ms for ms in MODEL_SETTINGS if ms.name == model_settings.name), None
)
if existing_model_settings:
MODEL_SETTINGS.remove(existing_model_settings)
MODEL_SETTINGS.append(model_settings)
except Exception as e:
raise Exception(f"Error loading model settings from {model_settings_fname}: {e}")
files_loaded.append(model_settings_fname)
return files_loaded
it appears to only try to load it in as a yaml file with:
try:
with open(model_settings_fname, "r") as model_settings_file:
model_settings_list = yaml.safe_load(model_settings_file)
also none of the settings keys match the names between the .json file and what the aider.models.ModelSettings() expect. The json file has:
"max_tokens"
"max_input_tokens"
"max_output_tokens"
"input_cost_per_token"
"output_cost_per_token"
"litellm_provider":
"mode":
whereas the ModelSettings() class appears to expect:
name: str
edit_format: str
weak_model_name: Optional[str] = None
use_repo_map: bool = False
send_undo_reply: bool = False
accepts_images: bool = False
lazy: bool = False
reminder_as_sys_msg: bool = False
examples_as_sys_msg: bool = False
can_prefill: bool = False
which is what is shown in the .yaml file example under the advanced configuration options in the docs.
Am I missing something simple? It doesn't look like it will load anything besides a .yaml file correctly.
Thanks for trying aider and filing this issue. This doc may be helpful:
https://aider.chat/docs/config/adv-model-settings.html
It looks like you are putting model SETTINGS into the METADATA json file. They belong in the settings.yml file.
@paul-gauthier I was using the --model-settings-file <filename> switch instead of --model-metadata-file <filename> I see now. But why did I have to explicitly point to the file when the docs say it would look for it in the root of my git repo and the directory where I launch aider?
Sorry, there's been a lot of different filenames discussed in this issue. Can you be explicit and show me a clean reproducible issue where aider is not reading a specific config file that it should be?
I'm going to close this issue for now, but feel free to add a comment here and I will re-open or file a new issue any time.