Revert "Python entry-point for CustomLLM subclasses (#15881)"

This reverts commit 559ae96e38.
This commit is contained in:
Ishaan Jaffer 2025-10-31 18:24:39 -07:00
parent 94c2c28f3d
commit 22eb2f8033
2 changed files with 0 additions and 62 deletions

View file

@ -36,7 +36,6 @@ import traceback
from dataclasses import dataclass, field
from functools import lru_cache, wraps
from importlib import resources
from importlib.metadata import entry_points
from inspect import iscoroutine
from io import StringIO
from os.path import abspath, dirname, join
@ -386,30 +385,10 @@ def print_verbose(
####### CLIENT ###################
# make it easy to log if completion/embedding runs succeeded or failed + see what happened | Non-Blocking
def load_custom_provider_entrypoints():
# Handle both Python 3.9 (returns dict) and Python 3.10+ (returns object with select method)
eps = entry_points()
if hasattr(eps, "select"):
# Python 3.10+
found_entry_points = tuple(eps.select(group="litellm")) # type: ignore
else:
# Python 3.9 and earlier - entry_points() returns a dict
found_entry_points = eps.get("litellm", ()) # type: ignore
for entry_point in found_entry_points:
# types are ignored because of circular dependency issues importing CustomLLM and CustomLLMItem
HandlerClass = entry_point.load()
handler = HandlerClass()
provider = {"provider": entry_point.name, "custom_handler": handler}
litellm.custom_provider_map.append(provider) # type: ignore
def custom_llm_setup():
"""
Add custom_llm provider to provider list
"""
load_custom_provider_entrypoints()
for custom_llm in litellm.custom_provider_map:
if custom_llm["provider"] not in litellm.provider_list:
litellm.provider_list.append(custom_llm["provider"])

View file

@ -537,44 +537,3 @@ async def test_simple_aembedding():
"embedding": [0.1, 0.2, 0.3],
"index": 1,
}
def test_custom_llm_provider_entrypoint():
# This test mocks the use of entry-points in pyproject.toml:
# [project.entry-point.litellm]
# custom_llm = <module>:MyCustomLLM
# another-custom-llm = <module>:AnotherCustomLLM
from litellm.utils import custom_llm_setup
from importlib.metadata import EntryPoints, EntryPoint
class AnotherCustomLLM(CustomLLM):
pass
providers = {
"custom_llm": MyCustomLLM,
"another-custom-llm": AnotherCustomLLM
}
def load(self):
return providers[self.name]
entry_points = EntryPoints([
EntryPoint(group="litellm", name="custom_llm", value="package.module:MyCustomLLM"),
EntryPoint(group="litellm", name="another-custom-llm", value="package.module:AnotherCustomLLM"),
])
with patch("importlib.metadata.EntryPoint.load", load):
with patch("litellm.utils.entry_points", return_value=entry_points):
assert litellm.custom_provider_map == []
assert litellm._custom_providers == []
custom_llm_setup()
assert litellm._custom_providers == ['custom_llm', 'another-custom-llm']
assert litellm.custom_provider_map[0]["provider"] == "custom_llm"
assert isinstance(litellm.custom_provider_map[0]["custom_handler"], CustomLLM)
assert litellm.custom_provider_map[1]["provider"] == "another-custom-llm"
assert isinstance(litellm.custom_provider_map[1]["custom_handler"], AnotherCustomLLM)