mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-05 02:41:56 +00:00
fix(api_route): add default API base
This commit is contained in:
parent
45c0e2f4cc
commit
8c608b311a
2 changed files with 20 additions and 14 deletions
|
|
@ -12,8 +12,6 @@ class APIRouteChatConfig(OpenAIGPTConfig):
|
|||
def _get_openai_compatible_provider_info(
|
||||
self, api_base: str | None, api_key: str | None
|
||||
) -> tuple[str | None, str | None]:
|
||||
resolved_api_base: Final = api_base or get_secret_str("API_ROUTE_BASE_URL")
|
||||
if not resolved_api_base:
|
||||
raise ValueError("API Route requires API_ROUTE_BASE_URL or api_base parameter.")
|
||||
resolved_api_base: Final = api_base or get_secret_str("API_ROUTE_BASE_URL") or "https://global.api-route.com/v1"
|
||||
resolved_api_key: Final = api_key or get_secret_str("API_ROUTE_API_KEY")
|
||||
return resolved_api_base, resolved_api_key
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
import json
|
||||
|
||||
import pytest
|
||||
|
||||
import litellm
|
||||
from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider
|
||||
from litellm.llms.api_route.chat.transformation import APIRouteChatConfig
|
||||
|
|
@ -39,17 +37,27 @@ def test_api_route_credentials_from_environment(monkeypatch):
|
|||
assert api_base == "https://env.example.com/v1"
|
||||
|
||||
|
||||
def test_api_route_requires_base_url(monkeypatch):
|
||||
def test_api_route_uses_default_base_url(monkeypatch):
|
||||
monkeypatch.delenv("API_ROUTE_BASE_URL", raising=False)
|
||||
|
||||
with pytest.raises(
|
||||
ValueError,
|
||||
match=r"API Route requires API_ROUTE_BASE_URL or api_base parameter\.",
|
||||
):
|
||||
APIRouteChatConfig()._get_openai_compatible_provider_info(
|
||||
api_base=None,
|
||||
api_key="test-key",
|
||||
)
|
||||
api_base, api_key = APIRouteChatConfig()._get_openai_compatible_provider_info(
|
||||
api_base=None,
|
||||
api_key="test-key",
|
||||
)
|
||||
|
||||
assert api_base == "https://global.api-route.com/v1"
|
||||
assert api_key == "test-key"
|
||||
|
||||
|
||||
def test_api_route_explicit_api_base_overrides_default(monkeypatch):
|
||||
monkeypatch.delenv("API_ROUTE_BASE_URL", raising=False)
|
||||
|
||||
api_base, _ = APIRouteChatConfig()._get_openai_compatible_provider_info(
|
||||
api_base="https://custom.example.com/v1",
|
||||
api_key="test-key",
|
||||
)
|
||||
|
||||
assert api_base == "https://custom.example.com/v1"
|
||||
|
||||
|
||||
def test_api_route_chat_completion_request(monkeypatch, respx_mock):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue