mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 18:54:30 +00:00
feat(utils.py): accept 'api_key' as param for validate_environment
Closes https://github.com/BerriAI/litellm/issues/4375
This commit is contained in:
parent
2163434ff3
commit
1ba3fcc3fb
2 changed files with 18 additions and 1 deletions
|
@ -258,6 +258,13 @@ def test_validate_environment_empty_model():
|
|||
raise Exception()
|
||||
|
||||
|
||||
def test_validate_environment_api_key():
|
||||
response_obj = validate_environment(model="gpt-3.5-turbo", api_key="sk-my-test-key")
|
||||
assert (
|
||||
response_obj["keys_in_environment"] is True
|
||||
), f"Missing keys={response_obj['missing_keys']}"
|
||||
|
||||
|
||||
@mock.patch.dict(os.environ, {"OLLAMA_API_BASE": "foo"}, clear=True)
|
||||
def test_validate_environment_ollama():
|
||||
for provider in ["ollama", "ollama_chat"]:
|
||||
|
|
|
@ -5048,12 +5048,15 @@ def create_proxy_transport_and_mounts():
|
|||
return sync_proxy_mounts, async_proxy_mounts
|
||||
|
||||
|
||||
def validate_environment(model: Optional[str] = None) -> dict:
|
||||
def validate_environment(
|
||||
model: Optional[str] = None, api_key: Optional[str] = None
|
||||
) -> dict:
|
||||
"""
|
||||
Checks if the environment variables are valid for the given model.
|
||||
|
||||
Args:
|
||||
model (Optional[str]): The name of the model. Defaults to None.
|
||||
api_key (Optional[str]): If the user passed in an api key, of their own.
|
||||
|
||||
Returns:
|
||||
dict: A dictionary containing the following keys:
|
||||
|
@ -5329,6 +5332,13 @@ def validate_environment(model: Optional[str] = None) -> dict:
|
|||
keys_in_environment = True
|
||||
else:
|
||||
missing_keys.append("NLP_CLOUD_API_KEY")
|
||||
|
||||
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
|
||||
return {"keys_in_environment": keys_in_environment, "missing_keys": missing_keys}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue