mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-30 01:04:59 +00:00
load litellm if model metadata json is present
This commit is contained in:
parent
f6023865f8
commit
b8d09e1f04
2 changed files with 14 additions and 10 deletions
|
@ -17,6 +17,8 @@ class LazyLiteLLM:
|
|||
_lazy_module = None
|
||||
|
||||
def __getattr__(self, name):
|
||||
if name == "_lazy_module":
|
||||
return super()
|
||||
self._load_litellm()
|
||||
return getattr(self._lazy_module, name)
|
||||
|
||||
|
|
|
@ -451,16 +451,17 @@ class Model:
|
|||
self.get_weak_model(weak_model)
|
||||
|
||||
def get_model_info(self, model):
|
||||
# Try and do this quickly, without triggering the litellm import
|
||||
spec = importlib.util.find_spec("litellm")
|
||||
if spec:
|
||||
origin = Path(spec.origin)
|
||||
fname = origin.parent / "model_prices_and_context_window_backup.json"
|
||||
if fname.exists():
|
||||
data = json.loads(fname.read_text())
|
||||
info = data.get(model)
|
||||
if info:
|
||||
return info
|
||||
if not litellm._lazy_module:
|
||||
# Try and do this quickly, without triggering the litellm import
|
||||
spec = importlib.util.find_spec("litellm")
|
||||
if spec:
|
||||
origin = Path(spec.origin)
|
||||
fname = origin.parent / "model_prices_and_context_window_backup.json"
|
||||
if fname.exists():
|
||||
data = json.loads(fname.read_text())
|
||||
info = data.get(model)
|
||||
if info:
|
||||
return info
|
||||
|
||||
# Do it the slow way...
|
||||
try:
|
||||
|
@ -670,6 +671,7 @@ def register_litellm_models(model_fnames):
|
|||
try:
|
||||
with open(model_fname, "r") as model_def_file:
|
||||
model_def = json.load(model_def_file)
|
||||
litellm._load_litellm()
|
||||
litellm.register_model(model_def)
|
||||
except Exception as e:
|
||||
raise Exception(f"Error loading model definition from {model_fname}: {e}")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue