mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 03:04:13 +00:00
(litellm sdk - perf improvement) - use O(1) set lookups for checking llm providers / models (#7672)
* fix get model info logic to use O(1) lookups * perf - use O(1) lookup for get llm provider
This commit is contained in:
parent
b3bd15e35a
commit
c999b4efe1
4 changed files with 11 additions and 5 deletions
|
@ -861,6 +861,7 @@ model_list = (
|
|||
+ azure_text_models
|
||||
)
|
||||
|
||||
model_list_set = set(model_list)
|
||||
|
||||
provider_list: List[Union[LlmProviders, str]] = list(LlmProviders)
|
||||
|
||||
|
|
|
@ -141,7 +141,7 @@ def get_llm_provider( # noqa: PLR0915
|
|||
# check if llm provider part of model name
|
||||
if (
|
||||
model.split("/", 1)[0] in litellm.provider_list
|
||||
and model.split("/", 1)[0] not in litellm.model_list
|
||||
and model.split("/", 1)[0] not in litellm.model_list_set
|
||||
and len(model.split("/"))
|
||||
> 1 # handle edge case where user passes in `litellm --model mistral` https://github.com/BerriAI/litellm/issues/1351
|
||||
):
|
||||
|
@ -210,7 +210,9 @@ def get_llm_provider( # noqa: PLR0915
|
|||
dynamic_api_key = get_secret_str("DEEPSEEK_API_KEY")
|
||||
elif endpoint == "https://api.friendli.ai/serverless/v1":
|
||||
custom_llm_provider = "friendliai"
|
||||
dynamic_api_key = get_secret_str("FRIENDLIAI_API_KEY") or get_secret("FRIENDLI_TOKEN")
|
||||
dynamic_api_key = get_secret_str(
|
||||
"FRIENDLIAI_API_KEY"
|
||||
) or get_secret("FRIENDLI_TOKEN")
|
||||
elif endpoint == "api.galadriel.com/v1":
|
||||
custom_llm_provider = "galadriel"
|
||||
dynamic_api_key = get_secret_str("GALADRIEL_API_KEY")
|
||||
|
|
|
@ -1817,6 +1817,10 @@ class LlmProviders(str, Enum):
|
|||
HUMANLOOP = "humanloop"
|
||||
|
||||
|
||||
# Create a set of all provider values for quick lookup
|
||||
LlmProvidersSet = {provider.value for provider in LlmProviders}
|
||||
|
||||
|
||||
class LiteLLMLoggingBaseClass:
|
||||
"""
|
||||
Base class for logging pre and post call
|
||||
|
|
|
@ -133,6 +133,7 @@ from litellm.types.utils import (
|
|||
Function,
|
||||
ImageResponse,
|
||||
LlmProviders,
|
||||
LlmProvidersSet,
|
||||
Message,
|
||||
ModelInfo,
|
||||
ModelInfoBase,
|
||||
|
@ -4108,9 +4109,7 @@ def _get_model_info_helper( # noqa: PLR0915
|
|||
):
|
||||
_model_info = None
|
||||
|
||||
if custom_llm_provider and custom_llm_provider in [
|
||||
provider.value for provider in LlmProviders
|
||||
]:
|
||||
if custom_llm_provider and custom_llm_provider in LlmProvidersSet:
|
||||
# Check if the provider string exists in LlmProviders enum
|
||||
provider_config = ProviderConfigManager.get_provider_model_info(
|
||||
model=model, provider=LlmProviders(custom_llm_provider)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue