The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
perf: optimize wrapper_async with CallTypes caching and reduced lookups (#20204)
ryan-crabbefadc04fbe279
diff --git a/litellm/utils.py b/litellm/utils.pyindex e67b967d75a..f3d14b455cd 100644--- a/litellm/utils.py+++ b/litellm/utils.py@@ -199,6 +199,8 @@ from litellm.types.utils import (all_litellm_params,)+_CALL_TYPE_ENUM_MAP: dict = {ct.value: ct for ct in CallTypes}+# +-----------------------------------------------+# | |# | Give Feedback / Get Help |@@ -1746,6 +1748,7 @@ def client(original_function): # noqa: PLR0915print_args_passed_to_litellm(original_function, args, kwargs)start_time = datetime.datetime.now()result = None+ _update_response_metadata = getattr(sys.modules[__name__], "update_response_metadata")logging_obj: Optional[LiteLLMLoggingObject] = kwargs.get("litellm_logging_obj", None)@@ -1786,9 +1789,10 @@ def client(original_function): # noqa: PLR0915)# [OPTIONAL] CHECK CACHE- print_verbose(- f"ASYNC kwargs[caching]: {kwargs.get('caching', False)}; litellm.cache: {litellm.cache}; kwargs.get('cache'): {kwargs.get('cache', None)}"- )+ if _is_debugging_on():+ print_verbose(+ f"ASYNC kwargs[caching]: {kwargs.get('caching', False)}; litellm.cache: {litellm.cache}; kwargs.get('cache'): {kwargs.get('cache', None)}"+ )_caching_handler_response: "Optional[CachingHandlerResponse]" = (await _llm_caching_handler._async_get_cache(model=model or "",@@ -1864,10 +1868,7 @@ def client(original_function): # noqa: PLR0915chunks, messages=kwargs.get("messages", None))else:- update_response_metadata = getattr(- sys.modules[__name__], "update_response_metadata"- )- update_response_metadata(+ _update_response_metadata(result=result,logging_obj=logging_obj,model=model,@@ -1887,11 +1888,12 @@ def client(original_function): # noqa: PLR0915rules_obj=rules_obj,)# Only run if call_type is a valid value in CallTypes- if call_type in [ct.value for ct in CallTypes]:+ _call_type_enum = _CALL_TYPE_ENUM_MAP.get(call_type)+ if _call_type_enum is not None:result = await async_post_call_success_deployment_hook(request_data=kwargs,response=result,- call_type=CallTypes(call_type),+ call_type=_call_type_enum,)## Add response to cache@@ -1931,10 +1933,7 @@ def client(original_function): # noqa: PLR0915end_time=end_time,)- update_response_metadata = getattr(- sys.modules[__name__], "update_response_metadata"- )- update_response_metadata(+ _update_response_metadata(result=result,logging_obj=logging_obj,model=model,