diff --git a/litellm/caching/llm_caching_handler.py b/litellm/caching/llm_caching_handler.py index 3bf1f80d08..898adfd7a5 100644 --- a/litellm/caching/llm_caching_handler.py +++ b/litellm/caching/llm_caching_handler.py @@ -14,10 +14,14 @@ class LLMClientCache(InMemoryCache): If none, use the key as is. """ try: - event_loop = asyncio.get_event_loop() + try: + event_loop = asyncio.get_running_loop() + except RuntimeError: + event_loop = asyncio.new_event_loop() + stringified_event_loop = str(id(event_loop)) return f"{key}-{stringified_event_loop}" - except Exception: # handle no current event loop + except Exception: # handle other potential errors return key def set_cache(self, key, value, **kwargs):