From b8f7ee516721cd060c6c19df942e10f2d4d3a580 Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Wed, 17 Apr 2024 16:43:20 -0400 Subject: [PATCH] chore(internal): add lru_cache helper function (#1329) --- src/openai/_utils/__init__.py | 1 + src/openai/_utils/_utils.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/openai/_utils/__init__.py b/src/openai/_utils/__init__.py index 5697894192..31b5b22799 100644 --- a/src/openai/_utils/__init__.py +++ b/src/openai/_utils/__init__.py @@ -6,6 +6,7 @@ is_list as is_list, is_given as is_given, is_tuple as is_tuple, + lru_cache as lru_cache, is_mapping as is_mapping, is_tuple_t as is_tuple_t, parse_date as parse_date, diff --git a/src/openai/_utils/_utils.py b/src/openai/_utils/_utils.py index 93c95517a9..5123a230f1 100644 --- a/src/openai/_utils/_utils.py +++ b/src/openai/_utils/_utils.py @@ -389,3 +389,11 @@ def get_async_library() -> str: return sniffio.current_async_library() except Exception: return "false" + + +def lru_cache(*, maxsize: int | None = 128) -> Callable[[CallableT], CallableT]: + """A version of functools.lru_cache that retains the type signature + for the wrapped function arguments. + """ + wrapper = functools.lru_cache(maxsize=maxsize) + return cast(Any, wrapper) # type: ignore[no-any-return]