Use executors in post-logging hooks (#14332)

This commit is contained in:
Arseny Boykov
2025-09-08 12:57:26 -07:00
committed by GitHub
parent 9a62b9bdb9
commit 05741a7c82
2 changed files with 17 additions and 11 deletions
+15 -11
View File
@@ -301,10 +301,12 @@ class LLMCachingHandler:
is_async=False,
)
threading.Thread(
target=logging_obj.success_handler,
args=(cached_result, start_time, end_time, cache_hit),
).start()
logging_obj.handle_sync_success_callbacks_for_async_calls(
result=cached_result,
start_time=start_time,
end_time=end_time,
cache_hit=cache_hit
)
cache_key = litellm.cache._get_preset_cache_key_from_kwargs(
**kwargs
)
@@ -530,15 +532,17 @@ class LLMCachingHandler:
end_time (datetime): The end time of the operation.
cache_hit (bool): Whether it was a cache hit.
"""
asyncio.create_task(
logging_obj.async_success_handler(
cached_result, start_time, end_time, cache_hit
from litellm.litellm_core_utils.logging_worker import GLOBAL_LOGGING_WORKER
GLOBAL_LOGGING_WORKER.ensure_initialized_and_enqueue(
async_coroutine=logging_obj.async_success_handler(
result=cached_result, start_time=start_time, end_time=end_time, cache_hit=cache_hit
)
)
threading.Thread(
target=logging_obj.success_handler,
args=(cached_result, start_time, end_time, cache_hit),
).start()
logging_obj.handle_sync_success_callbacks_for_async_calls(
result=cached_result, start_time=start_time, end_time=end_time, cache_hit=cache_hit
)
async def _retrieve_from_cache(
self, call_type: str, kwargs: Dict[str, Any], args: Tuple[Any, ...]
@@ -2774,6 +2774,7 @@ class Logging(LiteLLMLoggingBaseClass):
result: Any,
start_time: datetime.datetime,
end_time: datetime.datetime,
cache_hit: Optional[Any] = None,
) -> None:
"""
Handles calling success callbacks for Async calls.
@@ -2788,6 +2789,7 @@ class Logging(LiteLLMLoggingBaseClass):
result,
start_time,
end_time,
cache_hit,
)
def _should_run_sync_callbacks_for_async_calls(self) -> bool: