From bd30ae936cf0b82b1816b5e03be79ed49b9e82b7 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Sun, 25 Aug 2024 07:52:48 -0700 Subject: [PATCH] feat: Fetch model info from GitHub first, then fall back to local resource --- aider/models.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/aider/models.py b/aider/models.py index fcdd2a54f..6fa409404 100644 --- a/aider/models.py +++ b/aider/models.py @@ -452,15 +452,27 @@ class Model(ModelSettings): if not litellm._lazy_module: # Try and do this quickly, without triggering the litellm import try: - with importlib.resources.open_text( - "litellm", "model_prices_and_context_window_backup.json" - ) as f: - content = json.load(f) + # First, attempt to fetch from GitHub + import requests + url = "https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json" + response = requests.get(url, timeout=5) + if response.status_code == 200: + content = response.json() info = content.get(model) if info: return info except Exception: - pass # If there's any error, fall back to the slow way + # If fetching from GitHub fails, fall back to local resource + try: + with importlib.resources.open_text( + "litellm", "model_prices_and_context_window_backup.json" + ) as f: + content = json.load(f) + info = content.get(model) + if info: + return info + except Exception: + pass # If there's any error, fall back to the slow way # Do it the slow way... try: