mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 16:54:59 +00:00
refactor: Defer litellm registration to improve loading performance
This commit is contained in:
parent
44365651a6
commit
5ad8bb1830
1 changed files with 10 additions and 3 deletions
|
@ -85,6 +85,8 @@ MODEL_ALIASES = {
|
||||||
"r1": "deepseek/deepseek-reasoner",
|
"r1": "deepseek/deepseek-reasoner",
|
||||||
"flash": "gemini/gemini-2.0-flash-exp",
|
"flash": "gemini/gemini-2.0-flash-exp",
|
||||||
}
|
}
|
||||||
|
# Deferred model definitions loaded from metadata files
|
||||||
|
LITELLM_MODEL_DEFS = []
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -238,6 +240,12 @@ class Model(ModelSettings):
|
||||||
self.get_editor_model(editor_model, editor_edit_format)
|
self.get_editor_model(editor_model, editor_edit_format)
|
||||||
|
|
||||||
def get_model_info(self, model):
|
def get_model_info(self, model):
|
||||||
|
global LITELLM_MODEL_DEFS
|
||||||
|
if LITELLM_MODEL_DEFS:
|
||||||
|
litellm._load_litellm()
|
||||||
|
for model_def in LITELLM_MODEL_DEFS:
|
||||||
|
litellm.register_model(model_def)
|
||||||
|
LITELLM_MODEL_DEFS.clear()
|
||||||
return model_info_manager.get_model_info(model)
|
return model_info_manager.get_model_info(model)
|
||||||
|
|
||||||
def _copy_fields(self, source):
|
def _copy_fields(self, source):
|
||||||
|
@ -665,9 +673,8 @@ def register_litellm_models(model_fnames):
|
||||||
if not model_def:
|
if not model_def:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# only load litellm if we have actual data
|
# Defer registration with litellm to faster path.
|
||||||
litellm._load_litellm()
|
LITELLM_MODEL_DEFS.append(model_def)
|
||||||
litellm.register_model(model_def)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise Exception(f"Error loading model definition from {model_fname}: {e}")
|
raise Exception(f"Error loading model definition from {model_fname}: {e}")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue