mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-03 11:14:59 +00:00
feat: Fetch model info from GitHub first, then fall back to local resource
This commit is contained in:
parent
63c6bffb46
commit
bd30ae936c
1 changed files with 17 additions and 5 deletions
|
@ -452,15 +452,27 @@ class Model(ModelSettings):
|
||||||
if not litellm._lazy_module:
|
if not litellm._lazy_module:
|
||||||
# Try and do this quickly, without triggering the litellm import
|
# Try and do this quickly, without triggering the litellm import
|
||||||
try:
|
try:
|
||||||
with importlib.resources.open_text(
|
# First, attempt to fetch from GitHub
|
||||||
"litellm", "model_prices_and_context_window_backup.json"
|
import requests
|
||||||
) as f:
|
url = "https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json"
|
||||||
content = json.load(f)
|
response = requests.get(url, timeout=5)
|
||||||
|
if response.status_code == 200:
|
||||||
|
content = response.json()
|
||||||
info = content.get(model)
|
info = content.get(model)
|
||||||
if info:
|
if info:
|
||||||
return info
|
return info
|
||||||
except Exception:
|
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...
|
# Do it the slow way...
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue