mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
fix(cloudflare): treat empty CLOUDFLARE_ACCOUNT_ID as unset
An empty or whitespace-only CLOUDFLARE_ACCOUNT_ID slipped past the None guard and built .../accounts//ai/v1, producing the same confusing 404 the PR set out to prevent. Normalize the secret with normalize_nonempty_secret_str so blank values raise the explicit missing-account-id error instead.
This commit is contained in:
parent
b7367cf8e7
commit
2b956f3030
2 changed files with 21 additions and 2 deletions
|
|
@ -5,7 +5,10 @@ import httpx
|
|||
from litellm._logging import verbose_logger
|
||||
from litellm.llms.base_llm.chat.transformation import BaseLLMException
|
||||
from litellm.llms.openai.chat.gpt_transformation import OpenAIGPTConfig
|
||||
from litellm.secret_managers.main import get_secret_str
|
||||
from litellm.secret_managers.main import (
|
||||
get_secret_str,
|
||||
normalize_nonempty_secret_str,
|
||||
)
|
||||
from litellm.types.llms.openai import AllMessageValues
|
||||
|
||||
|
||||
|
|
@ -45,7 +48,9 @@ class CloudflareChatConfig(OpenAIGPTConfig):
|
|||
@staticmethod
|
||||
def _resolve_api_base(api_base: Optional[str]) -> str:
|
||||
if not api_base:
|
||||
account_id = get_secret_str("CLOUDFLARE_ACCOUNT_ID")
|
||||
account_id = normalize_nonempty_secret_str(
|
||||
get_secret_str("CLOUDFLARE_ACCOUNT_ID")
|
||||
)
|
||||
if account_id is None:
|
||||
raise ValueError(
|
||||
"Missing CLOUDFLARE_ACCOUNT_ID - set CLOUDFLARE_ACCOUNT_ID in the environment or pass api_base explicitly"
|
||||
|
|
|
|||
|
|
@ -100,6 +100,20 @@ def test_get_complete_url_raises_when_account_id_and_base_missing(monkeypatch):
|
|||
)
|
||||
|
||||
|
||||
def test_get_complete_url_raises_when_account_id_is_empty(monkeypatch):
|
||||
monkeypatch.setenv("CLOUDFLARE_ACCOUNT_ID", " ")
|
||||
config = CloudflareChatConfig()
|
||||
|
||||
with pytest.raises(ValueError, match="Missing CLOUDFLARE_ACCOUNT_ID"):
|
||||
config.get_complete_url(
|
||||
api_base=None,
|
||||
api_key="cf-key",
|
||||
model="@cf/meta/llama-2-7b-chat-int8",
|
||||
optional_params={},
|
||||
litellm_params={},
|
||||
)
|
||||
|
||||
|
||||
def test_get_complete_url_migrates_legacy_ai_run_base():
|
||||
config = CloudflareChatConfig()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue