(feat) add pre-commit hook to check model_prices_and_context_window.json litellm/model_prices_and_context_window_backup.json

This commit is contained in:
ishaan-jaff 2024-02-05 15:00:13 -08:00
parent a6836a0996
commit 8b571159fc
3 changed files with 34 additions and 21 deletions

View file

@ -10,6 +10,12 @@ repos:
exclude: ^litellm/tests/|^litellm/proxy/proxy_cli.py|^litellm/integrations/|^litellm/proxy/tests/ exclude: ^litellm/tests/|^litellm/proxy/proxy_cli.py|^litellm/integrations/|^litellm/proxy/tests/
additional_dependencies: [flake8-print] additional_dependencies: [flake8-print]
files: litellm/.*\.py files: litellm/.*\.py
- repo: local
hooks:
- id: check-files-match
name: Check if files match
entry: python3 ci_cd/check_files_match.py
language: system
- repo: local - repo: local
hooks: hooks:
- id: mypy - id: mypy
@ -17,11 +23,4 @@ repos:
entry: python3 -m mypy --ignore-missing-imports entry: python3 -m mypy --ignore-missing-imports
language: system language: system
types: [python] types: [python]
files: ^litellm/ files: ^litellm/
- repo: local
hooks:
- id: check-files-match
name: Check if files match
entry: python3 ci_cd/check_files_match.py
language: system
files: model_prices_and_context_window.json model_prices_and_context_window_backup.json

View file

@ -1,23 +1,37 @@
import sys import sys
import filecmp import filecmp
import difflib
def show_diff(file1, file2):
with open(file1, "r") as f1, open(file2, "r") as f2:
lines1 = f1.readlines()
lines2 = f2.readlines()
diff = difflib.unified_diff(lines1, lines2, lineterm="")
for line in diff:
print(line)
def main(argv=None): def main(argv=None):
if argv is None: print(
argv = sys.argv[1:] "comparing model_prices_and_context_window, and litellm/model_prices_and_context_window_backup.json files.......... checking they match",
argv,
)
if len(argv) != 2: file1 = "model_prices_and_context_window.json"
print("Usage: python check_files_match.py <file1> <file2>") file2 = "litellm/model_prices_and_context_window_backup.json"
return 1 cmp_result = filecmp.cmp(file1, file2, shallow=False)
if cmp_result:
file1 = argv[0] print(f"Passed ! Files {file1} and {file2} match.")
file2 = argv[1]
if filecmp.cmp(file1, file2, shallow=False):
print(f"Files {file1} and {file2} match.")
return 0 return 0
else: else:
print(f"Files {file1} and {file2} do not match.") # show the diff
print(f"Failed ! Files {file1} and {file2} do not match.")
print("\nDiff")
show_diff(file1, file2)
return 1 return 1

View file

@ -5,7 +5,7 @@
"max_output_tokens": 4096, "max_output_tokens": 4096,
"input_cost_per_token": 0.00003, "input_cost_per_token": 0.00003,
"output_cost_per_token": 0.00006, "output_cost_per_token": 0.00006,
"litellm_provider": "o", "litellm_provider": "openai",
"mode": "chat" "mode": "chat"
}, },
"gpt-4-0314": { "gpt-4-0314": {