mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
fix(cloudflare): treat empty api_base as unset when resolving URL
This commit is contained in:
parent
93add6a43b
commit
462a740424
2 changed files with 19 additions and 1 deletions
|
|
@ -44,7 +44,7 @@ class CloudflareChatConfig(OpenAIGPTConfig):
|
|||
|
||||
@staticmethod
|
||||
def _resolve_api_base(api_base: Optional[str]) -> str:
|
||||
if api_base is None:
|
||||
if not api_base:
|
||||
account_id = get_secret_str("CLOUDFLARE_ACCOUNT_ID")
|
||||
if account_id is None:
|
||||
raise ValueError(
|
||||
|
|
|
|||
|
|
@ -68,6 +68,24 @@ def test_get_complete_url_is_idempotent_for_full_base():
|
|||
)
|
||||
|
||||
|
||||
def test_get_complete_url_falls_back_to_account_id_when_base_is_empty(monkeypatch):
|
||||
monkeypatch.setenv("CLOUDFLARE_ACCOUNT_ID", "acct")
|
||||
config = CloudflareChatConfig()
|
||||
|
||||
url = config.get_complete_url(
|
||||
api_base="",
|
||||
api_key="cf-key",
|
||||
model="@cf/meta/llama-2-7b-chat-int8",
|
||||
optional_params={},
|
||||
litellm_params={},
|
||||
)
|
||||
|
||||
assert (
|
||||
url
|
||||
== "https://api.cloudflare.com/client/v4/accounts/acct/ai/v1/chat/completions"
|
||||
)
|
||||
|
||||
|
||||
def test_get_complete_url_raises_when_account_id_and_base_missing(monkeypatch):
|
||||
monkeypatch.delenv("CLOUDFLARE_ACCOUNT_ID", raising=False)
|
||||
config = CloudflareChatConfig()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue