59
59
import litellm .litellm_core_utils .json_validation_rule
60
60
import litellm .llms
61
61
import litellm .llms .gemini
62
+ # Import cached imports utilities
63
+ from litellm .litellm_core_utils .cached_imports import (
64
+ get_coroutine_checker ,
65
+ get_litellm_logging_class ,
66
+ get_set_callbacks ,
67
+ )
62
68
from litellm .caching ._internal_lru_cache import lru_cache_wrapper
63
69
from litellm .caching .caching import DualCache
64
70
from litellm .caching .caching_handler import CachingHandlerResponse , LLMCachingHandler
222
228
get_args ,
223
229
)
224
230
231
+
225
232
from openai import OpenAIError as OriginalError
226
233
227
234
from litellm .litellm_core_utils .thread_pool_executor import executor
@@ -521,16 +528,12 @@ def get_dynamic_callbacks(
521
528
522
529
523
530
524
- from litellm .litellm_core_utils .coroutine_checker import coroutine_checker
525
531
526
532
527
533
def function_setup ( # noqa: PLR0915
528
534
original_function : str , rules_obj , start_time , * args , ** kwargs
529
535
): # just run once to check if user wants to send their data anywhere - PostHog/Sentry/Slack/etc.
530
536
### NOTICES ###
531
- from litellm import Logging as LiteLLMLogging
532
- from litellm .litellm_core_utils .litellm_logging import set_callbacks
533
-
534
537
if litellm .set_verbose is True :
535
538
verbose_logger .warning (
536
539
"`litellm.set_verbose` is deprecated. Please set `os.environ['LITELLM_LOG'] = 'DEBUG'` for debug logs."
@@ -593,12 +596,12 @@ def function_setup( # noqa: PLR0915
593
596
+ litellm .failure_callback
594
597
)
595
598
)
596
- set_callbacks (callback_list = callback_list , function_id = function_id )
599
+ get_set_callbacks () (callback_list = callback_list , function_id = function_id )
597
600
## ASYNC CALLBACKS
598
601
if len (litellm .input_callback ) > 0 :
599
602
removed_async_items = []
600
603
for index , callback in enumerate (litellm .input_callback ): # type: ignore
601
- if coroutine_checker .is_async_callable (callback ):
604
+ if get_coroutine_checker () .is_async_callable (callback ):
602
605
litellm ._async_input_callback .append (callback )
603
606
removed_async_items .append (index )
604
607
@@ -608,7 +611,7 @@ def function_setup( # noqa: PLR0915
608
611
if len (litellm .success_callback ) > 0 :
609
612
removed_async_items = []
610
613
for index , callback in enumerate (litellm .success_callback ): # type: ignore
611
- if coroutine_checker .is_async_callable (callback ):
614
+ if get_coroutine_checker () .is_async_callable (callback ):
612
615
litellm .logging_callback_manager .add_litellm_async_success_callback (
613
616
callback
614
617
)
@@ -633,7 +636,7 @@ def function_setup( # noqa: PLR0915
633
636
if len (litellm .failure_callback ) > 0 :
634
637
removed_async_items = []
635
638
for index , callback in enumerate (litellm .failure_callback ): # type: ignore
636
- if coroutine_checker .is_async_callable (callback ):
639
+ if get_coroutine_checker () .is_async_callable (callback ):
637
640
litellm .logging_callback_manager .add_litellm_async_failure_callback (
638
641
callback
639
642
)
@@ -666,7 +669,7 @@ def function_setup( # noqa: PLR0915
666
669
removed_async_items = []
667
670
for index , callback in enumerate (kwargs ["success_callback" ]):
668
671
if (
669
- coroutine_checker .is_async_callable (callback )
672
+ get_coroutine_checker () .is_async_callable (callback )
670
673
or callback == "dynamodb"
671
674
or callback == "s3"
672
675
):
@@ -790,7 +793,7 @@ def function_setup( # noqa: PLR0915
790
793
call_type = call_type ,
791
794
):
792
795
stream = True
793
- logging_obj = LiteLLMLogging (
796
+ logging_obj = get_litellm_logging_class ()( # Victim for object pool
794
797
model = model , # type: ignore
795
798
messages = messages ,
796
799
stream = stream ,
@@ -903,7 +906,7 @@ def client(original_function): # noqa: PLR0915
903
906
rules_obj = Rules ()
904
907
905
908
def check_coroutine (value ) -> bool :
906
- return coroutine_checker .is_async_callable (value )
909
+ return get_coroutine_checker () .is_async_callable (value )
907
910
908
911
async def async_pre_call_deployment_hook (kwargs : Dict [str , Any ], call_type : str ):
909
912
"""
@@ -1597,7 +1600,7 @@ async def wrapper_async(*args, **kwargs): # noqa: PLR0915
1597
1600
setattr (e , "timeout" , timeout )
1598
1601
raise e
1599
1602
1600
- is_coroutine = coroutine_checker .is_async_callable (original_function )
1603
+ is_coroutine = get_coroutine_checker () .is_async_callable (original_function )
1601
1604
1602
1605
# Return the appropriate wrapper based on the original function type
1603
1606
if is_coroutine :
0 commit comments