This commit is contained in:
Paul Gauthier 2024-04-22 14:42:46 -07:00
parent 1c70e248aa
commit 6901f92f96
2 changed files with 41 additions and 36 deletions

View file

@ -21,36 +21,6 @@ os.environ["OR_SITE_URL"] = "http://aider.chat"
os.environ["OR_APP_NAME"] = "Aider"
def sanity_check_model(io, model):
show = False
if model.missing_keys:
show = True
io.tool_error(f"Model {model}: Missing these environment variables:")
for key in model.missing_keys:
io.tool_error(f"- {key}")
elif not model.keys_in_environment:
show = True
io.tool_error(f"Model {model}: Unknown which environment variables are required.")
if not model.info:
show = True
io.tool_error(
f"Model {model}: Unknown model, context window size and token costs unavailable."
)
possible_matches = models.fuzzy_match_models(model.name)
if possible_matches:
io.tool_error("Did you mean one of these?")
for match in possible_matches:
io.tool_error(f"- {match}")
if show:
io.tool_error("For more info see https://aider.chat/docs/llms.html#model-warnings")
return False
def get_git_root():
"""Try and guess the git repo, since the conf.yml can be at the repo root"""
try:
@ -634,12 +604,7 @@ def main(argv=None, input=None, output=None, force_git_root=None):
main_model = models.Model(args.model, weak_model=args.weak_model)
missing_model_info = False
if not sanity_check_model(io, main_model):
missing_model_info = True
if main_model.weak_model and main_model.weak_model is not main_model:
if not sanity_check_model(io, main_model.weak_model):
missing_model_info = True
missing_model_info = models.sanity_check_models(io, main_model)
if args.require_model_info and missing_model_info:
return 1

View file

@ -284,6 +284,46 @@ class Model:
return img.size
def sanity_check_models(io, main_model):
missing_model_info = False
if not sanity_check_model(io, main_model):
missing_model_info = True
if main_model.weak_model and main_model.weak_model is not main_model:
if not sanity_check_model(io, main_model.weak_model):
missing_model_info = True
return missing_model_info
def sanity_check_model(io, model):
show = False
if model.missing_keys:
show = True
io.tool_error(f"Model {model}: Missing these environment variables:")
for key in model.missing_keys:
io.tool_error(f"- {key}")
elif not model.keys_in_environment:
show = True
io.tool_error(f"Model {model}: Unknown which environment variables are required.")
if not model.info:
show = True
io.tool_error(
f"Model {model}: Unknown model, context window size and token costs unavailable."
)
possible_matches = fuzzy_match_models(model.name)
if possible_matches:
io.tool_error("Did you mean one of these?")
for match in possible_matches:
io.tool_error(f"- {match}")
if show:
io.tool_error("For more info see https://aider.chat/docs/llms.html#model-warnings")
return False
def fuzzy_match_models(name):
models = litellm.model_cost.keys()