diff --git a/weave/__init__.py b/weave/__init__.py index c90e875820c..1b352f5f7aa 100644 --- a/weave/__init__.py +++ b/weave/__init__.py @@ -1,5 +1,7 @@ """The top-level functions and classes for working with Weave.""" +from typing import Any + from weave import version from weave.trace.api import * @@ -18,6 +20,18 @@ ThreadPoolExecutor, # noqa: F401 ) + +def __getattr__(name: str) -> Any: + """This function defines module-level lazy imports. + + The scorer module is particularly heavy, so we defer to speed up weave import.""" + if name == "Scorer": + from weave.flow.scorer import Scorer + + return Scorer + raise AttributeError(f"module {__name__} has no attribute {name}") + + # Alias for succinct code P = EasyPrompt