Better unknown model warnings

This commit is contained in:
Paul Gauthier 2024-04-22 14:07:32 -07:00
parent f1ce673f78
commit efd3c39e50
4 changed files with 125 additions and 69 deletions

View file

@ -21,6 +21,36 @@ 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:
@ -277,7 +307,7 @@ def main(argv=None, input=None, output=None, force_git_root=None):
model_group.add_argument(
"--require-model-info",
action=argparse.BooleanOptionalAction,
default=True,
default=False,
help="Only work with models that have meta-data available (default: True)",
)
model_group.add_argument(
@ -602,13 +632,15 @@ def main(argv=None, input=None, output=None, force_git_root=None):
if args.openai_organization_id:
os.environ["OPENAI_ORGANIZATION"] = args.openai_organization_id
# Check in advance that we have model metadata
try:
main_model = models.Model(
args.model, weak_model=args.weak_model, require_model_info=args.require_model_info
)
except (models.NoModelInfo, models.ModelEnvironmentError) as err:
io.tool_error(str(err))
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
if args.require_model_info and missing_model_info:
return 1
try: