aboutsummaryrefslogtreecommitdiff
path: root/.venv/lib/python3.12/site-packages/litellm/caching/_internal_lru_cache.py
diff options
context:
space:
mode:
authorS. Solomon Darnell2025-03-28 21:52:21 -0500
committerS. Solomon Darnell2025-03-28 21:52:21 -0500
commit4a52a71956a8d46fcb7294ac71734504bb09bcc2 (patch)
treeee3dc5af3b6313e921cd920906356f5d4febc4ed /.venv/lib/python3.12/site-packages/litellm/caching/_internal_lru_cache.py
parentcc961e04ba734dd72309fb548a2f97d67d578813 (diff)
downloadgn-ai-4a52a71956a8d46fcb7294ac71734504bb09bcc2.tar.gz
two version of R2R are hereHEADmaster
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.py30
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