add enforce_llms_folder_style (#7175)

This commit is contained in:
Ishaan Jaff 2024-12-11 01:01:49 -08:00 committed by GitHub
parent b9b34a7b99
commit 5d1274cb6e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 14 deletions

View file

@ -816,6 +816,7 @@ jobs:
- run: python ./tests/documentation_tests/test_router_settings.py - run: python ./tests/documentation_tests/test_router_settings.py
- run: python ./tests/documentation_tests/test_api_docs.py - run: python ./tests/documentation_tests/test_api_docs.py
- run: python ./tests/code_coverage_tests/ensure_async_clients_test.py - run: python ./tests/code_coverage_tests/ensure_async_clients_test.py
- run: python ./tests/code_coverage_tests/enforce_llms_folder_style.py
- run: helm lint ./deploy/charts/litellm-helm - run: helm lint ./deploy/charts/litellm-helm
db_migration_disable_update_check: db_migration_disable_update_check:

View file

@ -2,15 +2,21 @@ import ast
import os import os
import sys import sys
sys.path.insert( sys.path.insert(0, os.path.abspath("../.."))
0, os.path.abspath("../..")
)
import litellm import litellm
ALLOWED_FILES_IN_LLMS_FOLDER = ["__init__", "base", "base_llm", "custom_httpx", "custom_llm", "deprecated_providers"] ALLOWED_FILES_IN_LLMS_FOLDER = [
"__init__",
"base",
"base_llm",
"custom_httpx",
"custom_llm",
"deprecated_providers",
]
def get_unique_names_from_llms_dir(base_dir="./litellm/llms/"):
def get_unique_names_from_llms_dir(base_dir: str):
""" """
Returns a set of unique file and folder names from the root level of litellm/llms directory, Returns a set of unique file and folder names from the root level of litellm/llms directory,
excluding file extensions and __init__.py excluding file extensions and __init__.py
@ -41,21 +47,26 @@ def run_lint_check(unique_names):
_all_litellm_providers = [str(provider.value) for provider in litellm.LlmProviders] _all_litellm_providers = [str(provider.value) for provider in litellm.LlmProviders]
violations = [] violations = []
for name in unique_names: for name in unique_names:
if name.lower() not in _all_litellm_providers and name not in ALLOWED_FILES_IN_LLMS_FOLDER: if (
name.lower() not in _all_litellm_providers
and name not in ALLOWED_FILES_IN_LLMS_FOLDER
):
violations.append(name) violations.append(name)
if len(violations) > 0: if len(violations) > 0:
raise ValueError(f"There are {len(violations)} violations in the llms folder. \n\n {violations}. \n\n Valid providers: {_all_litellm_providers}") raise ValueError(
f"There are {len(violations)} violations in the llms folder. \n\n {violations}. \n\n Valid providers: {_all_litellm_providers}"
)
def main(): def main():
llms_dir = "./litellm/llms/" # Update this path if needed llms_dir = "./litellm/llms/" # Update this path if needed
llms_dir = "../../litellm/llms/" # LOCAL TESTING # llms_dir = "../../litellm/llms/" # LOCAL TESTING
unique_names = get_unique_names_from_llms_dir(llms_dir) unique_names = get_unique_names_from_llms_dir(llms_dir)
print("Unique names in llms directory:", sorted(list(unique_names))) print("Unique names in llms directory:", sorted(list(unique_names)))
run_lint_check(unique_names) run_lint_check(unique_names)
if __name__ == "__main__": if __name__ == "__main__":
main() main()