mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-13 23:11:40 +00:00
fix(cognition): keep the caller api key when autodetecting a JSON provider
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
e8777610a7
commit
702120b143
2 changed files with 16 additions and 1 deletions
|
|
@ -351,7 +351,7 @@ def get_llm_provider(
|
|||
dynamic_api_key = get_secret_str("META_API_KEY")
|
||||
elif (json_provider := JSONProviderRegistry.get_by_base_url(endpoint)) is not None:
|
||||
custom_llm_provider = json_provider.slug
|
||||
dynamic_api_key = get_secret_str(json_provider.api_key_env)
|
||||
dynamic_api_key = api_key if api_key is not None else get_secret_str(json_provider.api_key_env)
|
||||
|
||||
if api_base is not None and not isinstance(api_base, str):
|
||||
raise Exception(f"api base needs to be a string. api_base={api_base}")
|
||||
|
|
|
|||
|
|
@ -79,6 +79,21 @@ class TestCognitionProviderIdentity:
|
|||
assert api_base == "https://api.cognition.ai/v1"
|
||||
assert api_key == "sk-cognition-env"
|
||||
|
||||
def test_autodetected_api_base_keeps_the_caller_api_key(self, monkeypatch: pytest.MonkeyPatch):
|
||||
from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider
|
||||
|
||||
monkeypatch.setenv("COGNITION_API_KEY", "sk-cognition-env")
|
||||
|
||||
_, provider, api_key, _ = get_llm_provider(
|
||||
model="swe-1.7",
|
||||
custom_llm_provider=None,
|
||||
api_base="https://api.cognition.ai/v1",
|
||||
api_key="sk-cognition-caller",
|
||||
)
|
||||
|
||||
assert provider == "cognition"
|
||||
assert api_key == "sk-cognition-caller"
|
||||
|
||||
def test_env_api_key_is_read_from_cognition_variable(self, monkeypatch: pytest.MonkeyPatch):
|
||||
from litellm.llms.openai_like.dynamic_config import create_config_class
|
||||
from litellm.llms.openai_like.json_loader import JSONProviderRegistry
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue