From 11261a9accafb0061ae6369596570d8a6163bc91 Mon Sep 17 00:00:00 2001 From: William Fu-Hinthorn <13333726+hinthornw@users.noreply.github.com> Date: Tue, 20 Aug 2024 10:33:56 -0700 Subject: [PATCH] once --- python/langsmith/_internal/_beta_decorator.py | 9 ++++++--- python/langsmith/async_client.py | 5 +---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/python/langsmith/_internal/_beta_decorator.py b/python/langsmith/_internal/_beta_decorator.py index 433ade058..12350d533 100644 --- a/python/langsmith/_internal/_beta_decorator.py +++ b/python/langsmith/_internal/_beta_decorator.py @@ -7,12 +7,15 @@ class LangSmithBetaWarning(UserWarning): """This is a warning specific to the LangSmithBeta module.""" +@functools.lru_cache(maxsize=100) +def _warn_once(message: str) -> None: + warnings.warn(message, LangSmithBetaWarning, stacklevel=2) + + def warn_beta(func: Callable) -> Callable: @functools.wraps(func) def wrapper(*args, **kwargs): - warnings.warn( - f"Function {func.__name__} is in beta.", LangSmithBetaWarning, stacklevel=2 - ) + _warn_once(f"Function {func.__name__} is in beta.") return func(*args, **kwargs) return wrapper diff --git a/python/langsmith/async_client.py b/python/langsmith/async_client.py index bea423cfd..1dc6f7119 100644 --- a/python/langsmith/async_client.py +++ b/python/langsmith/async_client.py @@ -5,7 +5,6 @@ import asyncio import datetime import uuid -import warnings from typing import ( Any, AsyncIterator, @@ -47,9 +46,7 @@ def __init__( retry_config: Optional[Mapping[str, Any]] = None, ): """Initialize the async client.""" - warnings.warn( - "Class AsyncClient is in beta.", ls_beta.LangSmithBetaWarning, stacklevel=2 - ) + ls_beta._warn_once("Class AsyncClient is in beta.") self._retry_config = retry_config or {"max_retries": 3} _headers = { "Content-Type": "application/json",