mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-18 09:45:23 +00:00
fix(utils): warn when a custom_provider_map name matches a built-in provider
This commit is contained in:
parent
754e5f1e2d
commit
44bb10d934
2 changed files with 34 additions and 0 deletions
|
|
@ -606,9 +606,23 @@ def custom_llm_setup():
|
|||
litellm.provider_list.append(custom_llm["provider"])
|
||||
|
||||
if custom_llm["provider"] not in litellm._custom_providers:
|
||||
_warn_if_built_in_provider_shadows_custom_handler(custom_llm["provider"])
|
||||
litellm._custom_providers.append(custom_llm["provider"])
|
||||
|
||||
|
||||
def _warn_if_built_in_provider_shadows_custom_handler(provider: str) -> None:
|
||||
from litellm.llms.openai_like.json_loader import JSONProviderRegistry
|
||||
|
||||
if provider not in LlmProvidersSet and not JSONProviderRegistry.exists(provider):
|
||||
return
|
||||
verbose_logger.warning(
|
||||
"custom_provider_map provider '%s' has the same name as a built-in LiteLLM provider, which handles "
|
||||
"'%s/' models instead of your custom_handler. Rename the provider and its models to use your handler",
|
||||
provider,
|
||||
provider,
|
||||
)
|
||||
|
||||
|
||||
def add_custom_logger_callback_to_specific_event(callback: str, logging_event: Literal["success", "failure"]) -> None:
|
||||
"""
|
||||
Add a custom logger callback to the specific event
|
||||
|
|
|
|||
|
|
@ -10882,3 +10882,23 @@ def test_get_optional_params_forwards_a_tool_config_cache_point_to_a_downstream_
|
|||
)
|
||||
|
||||
assert optional_params["extra_body"] == {"kept": True, "cache_control_injection_points": [point]}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("provider", "expected_warnings"),
|
||||
(("streamlake", 1), ("veniceai", 1), ("my-own-llm", 0)),
|
||||
)
|
||||
def test_custom_provider_named_like_a_built_in_warns_once(
|
||||
provider: str, expected_warnings: int, monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
monkeypatch.setattr(litellm, "custom_provider_map", [{"provider": provider, "custom_handler": litellm.CustomLLM()}])
|
||||
monkeypatch.setattr(litellm, "provider_list", list(litellm.provider_list))
|
||||
monkeypatch.setattr(litellm, "_custom_providers", [])
|
||||
|
||||
with caplog.at_level(logging.WARNING, logger=verbose_logger.name):
|
||||
litellm.utils.custom_llm_setup()
|
||||
litellm.utils.custom_llm_setup()
|
||||
|
||||
warnings: Final = [r for r in caplog.records if f"provider '{provider}'" in r.getMessage()]
|
||||
assert len(warnings) == expected_warnings
|
||||
assert provider in litellm._custom_providers
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue