From 8b571159fcd2bd25c2f9a7e75b3ab58fa20dcd24 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Mon, 5 Feb 2024 15:00:13 -0800 Subject: [PATCH] (feat) add pre-commit hook to check model_prices_and_context_window.json litellm/model_prices_and_context_window_backup.json --- .pre-commit-config.yaml | 15 ++++++------ ci_cd/check_files_match.py | 36 +++++++++++++++++++--------- model_prices_and_context_window.json | 2 +- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 95f19f222040..8978e0d1a0b9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,6 +10,12 @@ repos: exclude: ^litellm/tests/|^litellm/proxy/proxy_cli.py|^litellm/integrations/|^litellm/proxy/tests/ additional_dependencies: [flake8-print] 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 hooks: - id: mypy @@ -17,11 +23,4 @@ repos: entry: python3 -m mypy --ignore-missing-imports language: system types: [python] - 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 \ No newline at end of file + files: ^litellm/ \ No newline at end of file diff --git a/ci_cd/check_files_match.py b/ci_cd/check_files_match.py index 0b5a0fab1d6e..a9f081ce8d4c 100644 --- a/ci_cd/check_files_match.py +++ b/ci_cd/check_files_match.py @@ -1,23 +1,37 @@ import sys import filecmp +import difflib -def main(argv=None): - if argv is None: - argv = sys.argv[1:] +def show_diff(file1, file2): + with open(file1, "r") as f1, open(file2, "r") as f2: + lines1 = f1.readlines() + lines2 = f2.readlines() - if len(argv) != 2: - print("Usage: python check_files_match.py ") - return 1 + diff = difflib.unified_diff(lines1, lines2, lineterm="") + + for line in diff: + print(line) - file1 = argv[0] - file2 = argv[1] - if filecmp.cmp(file1, file2, shallow=False): - print(f"Files {file1} and {file2} match.") +def main(argv=None): + print( + "comparing model_prices_and_context_window, and litellm/model_prices_and_context_window_backup.json files.......... checking they match", + argv, + ) + + file1 = "model_prices_and_context_window.json" + file2 = "litellm/model_prices_and_context_window_backup.json" + cmp_result = filecmp.cmp(file1, file2, shallow=False) + if cmp_result: + print(f"Passed ! Files {file1} and {file2} match.") return 0 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 diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json index 6087eccd99c4..b6ded001c93a 100644 --- a/model_prices_and_context_window.json +++ b/model_prices_and_context_window.json @@ -5,7 +5,7 @@ "max_output_tokens": 4096, "input_cost_per_token": 0.00003, "output_cost_per_token": 0.00006, - "litellm_provider": "o", + "litellm_provider": "openai", "mode": "chat" }, "gpt-4-0314": {