From e696102890d5293a227d8691d76ca231b8e67637 Mon Sep 17 00:00:00 2001 From: Piyush Jain Date: Mon, 18 Nov 2024 15:26:56 -0800 Subject: [PATCH] Added version ceiling for anthropic token count. --- libs/aws/langchain_aws/utils.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libs/aws/langchain_aws/utils.py b/libs/aws/langchain_aws/utils.py index ff9188a2..95e49529 100644 --- a/libs/aws/langchain_aws/utils.py +++ b/libs/aws/langchain_aws/utils.py @@ -10,6 +10,18 @@ def enforce_stop_tokens(text: str, stop: List[str]) -> str: def _get_anthropic_client() -> Any: try: import anthropic + from packaging import version + + max_supported_version = version.parse("0.38.0") + anthropic_version = version.parse(anthropic.__version__) + + if anthropic_version > max_supported_version: + raise NotImplementedError( + "Currently installed anthropic version {anthropic_version} is not " + "supported. Please use ChatAnthropic.get_num_tokens_from_messages " + "instead." + ) + except ImportError: raise ImportError( "Could not import anthropic python package. "