mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-01 10:14:59 +00:00
fix: handle errors when creating cache directory in get_model_info
This commit is contained in:
parent
d94c1c0e1f
commit
671c633d8f
1 changed files with 26 additions and 14 deletions
|
@ -514,8 +514,15 @@ def get_model_info(model):
|
||||||
if not litellm._lazy_module:
|
if not litellm._lazy_module:
|
||||||
cache_dir = Path.home() / ".aider" / "caches"
|
cache_dir = Path.home() / ".aider" / "caches"
|
||||||
cache_file = cache_dir / "model_prices_and_context_window.json"
|
cache_file = cache_dir / "model_prices_and_context_window.json"
|
||||||
cache_dir.mkdir(parents=True, exist_ok=True)
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
cache_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
use_cache = True
|
||||||
|
except OSError:
|
||||||
|
# If we can't create the cache directory, we'll skip using the cache
|
||||||
|
use_cache = False
|
||||||
|
|
||||||
|
if use_cache:
|
||||||
current_time = time.time()
|
current_time = time.time()
|
||||||
cache_age = (
|
cache_age = (
|
||||||
current_time - cache_file.stat().st_mtime if cache_file.exists() else float("inf")
|
current_time - cache_file.stat().st_mtime if cache_file.exists() else float("inf")
|
||||||
|
@ -536,7 +543,12 @@ def get_model_info(model):
|
||||||
response = requests.get(model_info_url, timeout=5)
|
response = requests.get(model_info_url, timeout=5)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
content = response.json()
|
content = response.json()
|
||||||
|
if use_cache:
|
||||||
|
try:
|
||||||
cache_file.write_text(json.dumps(content, indent=4))
|
cache_file.write_text(json.dumps(content, indent=4))
|
||||||
|
except OSError:
|
||||||
|
# If we can't write to the cache file, we'll just skip caching
|
||||||
|
pass
|
||||||
res = get_model_flexible(model, content)
|
res = get_model_flexible(model, content)
|
||||||
if res:
|
if res:
|
||||||
return res
|
return res
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue