mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-18 04:28:19 +00:00
feat(utils.py): accept 'api_version' as param for validate_environment
This commit is contained in:
+10
-10
@@ -5207,6 +5207,7 @@ def validate_environment( # noqa: PLR0915
|
||||
model: Optional[str] = None,
|
||||
api_key: Optional[str] = None,
|
||||
api_base: Optional[str] = None,
|
||||
api_version: Optional[str] = None,
|
||||
) -> dict:
|
||||
"""
|
||||
Checks if the environment variables are valid for the given model.
|
||||
@@ -5552,19 +5553,18 @@ def validate_environment( # noqa: PLR0915
|
||||
else:
|
||||
missing_keys.append("NEBIUS_API_KEY")
|
||||
|
||||
def filter_missing_keys(keys: List[str], exclude_pattern: str) -> List[str]:
|
||||
"""Filter out keys that contain the exclude_pattern (case insensitive)."""
|
||||
return [key for key in keys if exclude_pattern not in key.lower()]
|
||||
|
||||
if api_key is not None:
|
||||
new_missing_keys = []
|
||||
for key in missing_keys:
|
||||
if "api_key" not in key.lower():
|
||||
new_missing_keys.append(key)
|
||||
missing_keys = new_missing_keys
|
||||
missing_keys = filter_missing_keys(missing_keys, "api_key")
|
||||
|
||||
if api_base is not None:
|
||||
new_missing_keys = []
|
||||
for key in missing_keys:
|
||||
if "api_base" not in key.lower():
|
||||
new_missing_keys.append(key)
|
||||
missing_keys = new_missing_keys
|
||||
missing_keys = filter_missing_keys(missing_keys, "api_base")
|
||||
|
||||
if api_version is not None:
|
||||
missing_keys = filter_missing_keys(missing_keys, "api_version")
|
||||
|
||||
if len(missing_keys) == 0: # no missing keys
|
||||
keys_in_environment = True
|
||||
|
||||
@@ -411,6 +411,13 @@ def test_validate_environment_api_key():
|
||||
), f"Missing keys={response_obj['missing_keys']}"
|
||||
|
||||
|
||||
def test_validate_environment_api_version():
|
||||
response_obj = validate_environment(model="azure/openai-deployment", api_key="sk-my-test-key", api_base="https://fake.openai.azure.com/", api_version="2024-02-15")
|
||||
assert (
|
||||
response_obj["keys_in_environment"] is True
|
||||
), f"Missing keys={response_obj['missing_keys']}"
|
||||
|
||||
|
||||
def test_validate_environment_api_base_dynamic():
|
||||
for provider in ["ollama", "ollama_chat"]:
|
||||
kv = validate_environment(provider + "/mistral", api_base="https://example.com")
|
||||
|
||||
Reference in New Issue
Block a user