mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-31 01:35:00 +00:00
feat: cache the fetched json in Path.home() / .aider / caches
This commit is contained in:
parent
5e50adb96f
commit
fb812acfe1
1 changed files with 16 additions and 2 deletions
|
@ -450,9 +450,22 @@ class Model(ModelSettings):
|
|||
|
||||
def get_model_info(self, model):
|
||||
if not litellm._lazy_module:
|
||||
# Try and do this quickly, without triggering the litellm import
|
||||
cache_dir = Path.home() / ".aider" / "caches"
|
||||
cache_file = cache_dir / "model_prices_and_context_window.json"
|
||||
cache_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
current_time = time.time()
|
||||
cache_age = current_time - cache_file.stat().st_mtime if cache_file.exists() else float('inf')
|
||||
|
||||
if cache_file.exists() and cache_age < 86400: # 86400 seconds = 1 day
|
||||
content = safe_read_json(cache_file)
|
||||
if content:
|
||||
info = content.get(model)
|
||||
if info:
|
||||
return info
|
||||
|
||||
# If cache doesn't exist or is old, fetch from GitHub
|
||||
try:
|
||||
# First, attempt to fetch from GitHub
|
||||
import requests
|
||||
|
||||
url = (
|
||||
|
@ -462,6 +475,7 @@ class Model(ModelSettings):
|
|||
response = requests.get(url, timeout=5)
|
||||
if response.status_code == 200:
|
||||
content = response.json()
|
||||
safe_write_json(cache_file, content)
|
||||
info = content.get(model)
|
||||
if info:
|
||||
return info
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue