diff options
author | S. Solomon Darnell | 2025-03-28 21:52:21 -0500 |
---|---|---|
committer | S. Solomon Darnell | 2025-03-28 21:52:21 -0500 |
commit | 4a52a71956a8d46fcb7294ac71734504bb09bcc2 (patch) | |
tree | ee3dc5af3b6313e921cd920906356f5d4febc4ed /.venv/lib/python3.12/site-packages/litellm/caching/_internal_lru_cache.py | |
parent | cc961e04ba734dd72309fb548a2f97d67d578813 (diff) | |
download | gn-ai-4a52a71956a8d46fcb7294ac71734504bb09bcc2.tar.gz |
Diffstat (limited to '.venv/lib/python3.12/site-packages/litellm/caching/_internal_lru_cache.py')
-rw-r--r-- | .venv/lib/python3.12/site-packages/litellm/caching/_internal_lru_cache.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/litellm/caching/_internal_lru_cache.py b/.venv/lib/python3.12/site-packages/litellm/caching/_internal_lru_cache.py new file mode 100644 index 00000000..54b0fe96 --- /dev/null +++ b/.venv/lib/python3.12/site-packages/litellm/caching/_internal_lru_cache.py @@ -0,0 +1,30 @@ +from functools import lru_cache +from typing import Callable, Optional, TypeVar + +T = TypeVar("T") + + +def lru_cache_wrapper( + maxsize: Optional[int] = None, +) -> Callable[[Callable[..., T]], Callable[..., T]]: + """ + Wrapper for lru_cache that caches success and exceptions + """ + + def decorator(f: Callable[..., T]) -> Callable[..., T]: + @lru_cache(maxsize=maxsize) + def wrapper(*args, **kwargs): + try: + return ("success", f(*args, **kwargs)) + except Exception as e: + return ("error", e) + + def wrapped(*args, **kwargs): + result = wrapper(*args, **kwargs) + if result[0] == "error": + raise result[1] + return result[1] + + return wrapped + + return decorator |