Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2887,9 +2887,9 @@ jobs:
- checkout

- run:
name: Copy model_prices_and_context_window File to model_prices_and_context_window_backup
name: Copy model_prices_and_context_window File to litellm package
command: |
cp model_prices_and_context_window.json litellm/model_prices_and_context_window_backup.json
cp model_prices_and_context_window.json litellm/model_prices_and_context_window.json
Comment thread
Chesars marked this conversation as resolved.
Resolved

- run:
name: Checkout code
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/simple_pypi_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:

- name: Copy model prices file
run: |
cp model_prices_and_context_window.json litellm/model_prices_and_context_window_backup.json
cp model_prices_and_context_window.json litellm/model_prices_and_context_window.json

- name: Build package
run: |
Expand Down
6 changes: 0 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,3 @@ repos:
hooks:
- id: poetry-check
files: ^(pyproject.toml|litellm-proxy-extras/pyproject.toml)$
- repo: local
hooks:
- id: check-files-match
name: Check if files match
entry: python3 ci_cd/check_files_match.py
language: system
32 changes: 0 additions & 32 deletions ci_cd/check_files_match.py

This file was deleted.

50 changes: 34 additions & 16 deletions litellm/litellm_core_utils/get_model_cost_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,48 @@
"""

import os
from pathlib import Path

import httpx


def _load_local_model_cost_map() -> dict:
"""Load model cost map from local filesystem.

Tries to load from:
1. Package resources (production, after pip install)
2. Project root (development)
"""
import json

# Try loading from package resources (production)
try:
import importlib.resources
with importlib.resources.files("litellm").joinpath(
"model_prices_and_context_window.json"
).open("r") as f:
return json.load(f)
except (FileNotFoundError, ModuleNotFoundError):
Comment thread
Chesars marked this conversation as resolved.
Resolved
pass
Comment thread
Chesars marked this conversation as resolved.
Resolved

# Try loading from project root (development)
try:
current_dir = Path(__file__).parent.parent.parent
model_cost_map_path = current_dir / "model_prices_and_context_window.json"
with open(model_cost_map_path, "r") as f:
return json.load(f)
except FileNotFoundError:
raise FileNotFoundError(
"Could not find model_prices_and_context_window.json in package or project root"
)
Comment thread
Chesars marked this conversation as resolved.
Resolved


def get_model_cost_map(url: str) -> dict:
if (
os.getenv("LITELLM_LOCAL_MODEL_COST_MAP", False)
or os.getenv("LITELLM_LOCAL_MODEL_COST_MAP", False) == "True"
):
import importlib.resources
import json

with importlib.resources.open_text(
"litellm", "model_prices_and_context_window_backup.json"
) as f:
content = json.load(f)
return content
return _load_local_model_cost_map()

try:
response = httpx.get(
Expand All @@ -35,11 +60,4 @@ def get_model_cost_map(url: str) -> dict:
content = response.json()
return content
except Exception:
import importlib.resources
import json

with importlib.resources.open_text(
"litellm", "model_prices_and_context_window_backup.json"
) as f:
content = json.load(f)
return content
return _load_local_model_cost_map()
Loading