mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-03 19:24:59 +00:00
Refactored error handling to display model name in case of unknown model.
This commit is contained in:
parent
fb3285ff77
commit
922559a15a
2 changed files with 22 additions and 10 deletions
|
@ -587,14 +587,14 @@ def main(argv=None, input=None, output=None, force_git_root=None):
|
||||||
io.tool_error(f"- {key}")
|
io.tool_error(f"- {key}")
|
||||||
return 1
|
return 1
|
||||||
elif not res["keys_in_environment"]:
|
elif not res["keys_in_environment"]:
|
||||||
io.tool_error(f"Unknown model {args.model}.")
|
io.tool_error(models.check_model_name(args.model))
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
# Check in advance that we have model metadata
|
# Check in advance that we have model metadata
|
||||||
try:
|
try:
|
||||||
main_model = models.Model(args.model, weak_model=args.weak_model)
|
main_model = models.Model(args.model, weak_model=args.weak_model)
|
||||||
except models.NoModelInfo as err:
|
except models.NoModelInfo as err:
|
||||||
io.tool_error(f"Unknown model {err}.")
|
io.tool_error(str(err))
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import difflib
|
||||||
|
import sys
|
||||||
import json
|
import json
|
||||||
import math
|
import math
|
||||||
from dataclasses import dataclass, fields
|
from dataclasses import dataclass, fields
|
||||||
|
@ -17,7 +19,7 @@ class NoModelInfo(Exception):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, model):
|
def __init__(self, model):
|
||||||
super().__init__(model)
|
super().__init__(check_model_name(model))
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -234,24 +236,34 @@ class Model:
|
||||||
return img.size
|
return img.size
|
||||||
|
|
||||||
|
|
||||||
import difflib
|
def check_model_name(model):
|
||||||
|
res = f"Unknown model: {model}"
|
||||||
|
|
||||||
|
possible_matches = fuzzy_match_models(model)
|
||||||
|
|
||||||
|
if possible_matches:
|
||||||
|
res += '\n\nDid you mean one of these:\n'
|
||||||
|
for match in possible_matches:
|
||||||
|
res += '\n- ' + match
|
||||||
|
|
||||||
|
return res
|
||||||
|
|
||||||
def fuzzy_match_models(name):
|
def fuzzy_match_models(name):
|
||||||
models = litellm.most_cost.keys()
|
models = litellm.model_cost.keys()
|
||||||
|
|
||||||
# Check for exact match first
|
# Check for exact match first
|
||||||
if name in models:
|
if name in models:
|
||||||
return [name]
|
return [name]
|
||||||
|
|
||||||
# Check for models containing the name
|
# Check for models containing the name
|
||||||
matching_models = [model for model in models if name in model]
|
matching_models = [model for model in models if name in model]
|
||||||
|
|
||||||
# If no matches found, check for slight misspellings
|
# If no matches found, check for slight misspellings
|
||||||
if not matching_models:
|
if not matching_models:
|
||||||
matching_models = difflib.get_close_matches(name, models, n=3, cutoff=0.8)
|
matching_models = difflib.get_close_matches(name, models, n=3, cutoff=0.8)
|
||||||
|
|
||||||
return matching_models
|
return matching_models
|
||||||
import sys
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv) != 2:
|
if len(sys.argv) != 2:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue