From 155c6a9b008cfe0f52a10a2d30324d42f07bc2a5 Mon Sep 17 00:00:00 2001 From: amirai21 <89905406+amirai21@users.noreply.github.com> Date: Tue, 5 Nov 2024 13:10:17 +0200 Subject: [PATCH] fix: adding depracation warning to all TSMs, custom models and datasets (#223) --- .../sagemaker/resources/sagemaker_answer.py | 3 +++ .../clients/sagemaker/resources/sagemaker_gec.py | 3 +++ .../sagemaker/resources/sagemaker_paraphrase.py | 3 +++ .../sagemaker/resources/sagemaker_summarize.py | 3 +++ ai21/clients/studio/resources/studio_answer.py | 3 +++ .../studio/resources/studio_custom_model.py | 7 +++++++ ai21/clients/studio/resources/studio_dataset.py | 7 +++++++ ai21/clients/studio/resources/studio_embed.py | 3 +++ ai21/clients/studio/resources/studio_gec.py | 3 +++ .../studio/resources/studio_improvements.py | 3 +++ .../studio/resources/studio_paraphrase.py | 3 +++ .../studio/resources/studio_segmentation.py | 3 +++ .../clients/studio/resources/studio_summarize.py | 3 +++ .../resources/studio_summarize_by_segment.py | 3 +++ ai21/version_utils.py | 16 ++++++++++++++++ 15 files changed, 66 insertions(+) create mode 100644 ai21/version_utils.py diff --git a/ai21/clients/sagemaker/resources/sagemaker_answer.py b/ai21/clients/sagemaker/resources/sagemaker_answer.py index 586e1ce8..4352a787 100644 --- a/ai21/clients/sagemaker/resources/sagemaker_answer.py +++ b/ai21/clients/sagemaker/resources/sagemaker_answer.py @@ -1,9 +1,11 @@ from ai21.clients.common.answer_base import Answer from ai21.clients.sagemaker.resources.sagemaker_resource import SageMakerResource, AsyncSageMakerResource from ai21.models import AnswerResponse +from ai21.version_utils import V3_DEPRECATION_MESSAGE, deprecated class SageMakerAnswer(SageMakerResource, Answer): + @deprecated(V3_DEPRECATION_MESSAGE) def create( self, context: str, @@ -17,6 +19,7 @@ def create( class AsyncSageMakerAnswer(AsyncSageMakerResource, Answer): + @deprecated(V3_DEPRECATION_MESSAGE) async def create( self, context: str, diff --git a/ai21/clients/sagemaker/resources/sagemaker_gec.py b/ai21/clients/sagemaker/resources/sagemaker_gec.py index e493eff4..80a1f1f0 100644 --- a/ai21/clients/sagemaker/resources/sagemaker_gec.py +++ b/ai21/clients/sagemaker/resources/sagemaker_gec.py @@ -1,9 +1,11 @@ from ai21.clients.common.gec_base import GEC from ai21.clients.sagemaker.resources.sagemaker_resource import SageMakerResource, AsyncSageMakerResource from ai21.models import GECResponse +from ai21.version_utils import V3_DEPRECATION_MESSAGE, deprecated class SageMakerGEC(SageMakerResource, GEC): + @deprecated(V3_DEPRECATION_MESSAGE) def create(self, text: str, **kwargs) -> GECResponse: body = self._create_body(text=text) @@ -13,6 +15,7 @@ def create(self, text: str, **kwargs) -> GECResponse: class AsyncSageMakerGEC(AsyncSageMakerResource, GEC): + @deprecated(V3_DEPRECATION_MESSAGE) async def create(self, text: str, **kwargs) -> GECResponse: body = self._create_body(text=text) diff --git a/ai21/clients/sagemaker/resources/sagemaker_paraphrase.py b/ai21/clients/sagemaker/resources/sagemaker_paraphrase.py index b277f40f..0deb584e 100644 --- a/ai21/clients/sagemaker/resources/sagemaker_paraphrase.py +++ b/ai21/clients/sagemaker/resources/sagemaker_paraphrase.py @@ -3,9 +3,11 @@ from ai21.clients.common.paraphrase_base import Paraphrase from ai21.clients.sagemaker.resources.sagemaker_resource import SageMakerResource, AsyncSageMakerResource from ai21.models import ParaphraseStyleType, ParaphraseResponse +from ai21.version_utils import V3_DEPRECATION_MESSAGE, deprecated class SageMakerParaphrase(SageMakerResource, Paraphrase): + @deprecated(V3_DEPRECATION_MESSAGE) def create( self, text: str, @@ -27,6 +29,7 @@ def create( class AsyncSageMakerParaphrase(AsyncSageMakerResource, Paraphrase): + @deprecated(V3_DEPRECATION_MESSAGE) async def create( self, text: str, diff --git a/ai21/clients/sagemaker/resources/sagemaker_summarize.py b/ai21/clients/sagemaker/resources/sagemaker_summarize.py index a3336292..27afcdc9 100644 --- a/ai21/clients/sagemaker/resources/sagemaker_summarize.py +++ b/ai21/clients/sagemaker/resources/sagemaker_summarize.py @@ -5,9 +5,11 @@ from ai21.clients.common.summarize_base import Summarize from ai21.clients.sagemaker.resources.sagemaker_resource import SageMakerResource, AsyncSageMakerResource from ai21.models import SummarizeResponse, SummaryMethod +from ai21.version_utils import V3_DEPRECATION_MESSAGE, deprecated class SageMakerSummarize(SageMakerResource, Summarize): + @deprecated(V3_DEPRECATION_MESSAGE) def create( self, source: str, @@ -30,6 +32,7 @@ def create( class AsyncSageMakerSummarize(AsyncSageMakerResource, Summarize): + @deprecated(V3_DEPRECATION_MESSAGE) async def create( self, source: str, diff --git a/ai21/clients/studio/resources/studio_answer.py b/ai21/clients/studio/resources/studio_answer.py index 9e5b95d9..948775b0 100644 --- a/ai21/clients/studio/resources/studio_answer.py +++ b/ai21/clients/studio/resources/studio_answer.py @@ -1,9 +1,11 @@ from ai21.clients.common.answer_base import Answer from ai21.clients.studio.resources.studio_resource import StudioResource, AsyncStudioResource from ai21.models import AnswerResponse +from ai21.version_utils import deprecated, V3_DEPRECATION_MESSAGE class StudioAnswer(StudioResource, Answer): + @deprecated(V3_DEPRECATION_MESSAGE) def create( self, context: str, @@ -16,6 +18,7 @@ def create( class AsyncStudioAnswer(AsyncStudioResource, Answer): + @deprecated(V3_DEPRECATION_MESSAGE) async def create( self, context: str, diff --git a/ai21/clients/studio/resources/studio_custom_model.py b/ai21/clients/studio/resources/studio_custom_model.py index 13bb2749..76ce63b7 100644 --- a/ai21/clients/studio/resources/studio_custom_model.py +++ b/ai21/clients/studio/resources/studio_custom_model.py @@ -3,9 +3,11 @@ from ai21.clients.common.custom_model_base import CustomModel from ai21.clients.studio.resources.studio_resource import StudioResource, AsyncStudioResource from ai21.models import CustomBaseModelResponse +from ai21.version_utils import deprecated, V3_DEPRECATION_MESSAGE class StudioCustomModel(StudioResource, CustomModel): + @deprecated(V3_DEPRECATION_MESSAGE) def create( self, dataset_id: str, @@ -26,14 +28,17 @@ def create( ) self._post(path=f"/{self._module_name}", body=body, response_cls=None) + @deprecated(V3_DEPRECATION_MESSAGE) def list(self) -> List[CustomBaseModelResponse]: return self._get(path=f"/{self._module_name}", response_cls=List[CustomBaseModelResponse]) + @deprecated(V3_DEPRECATION_MESSAGE) def get(self, resource_id: str) -> CustomBaseModelResponse: return self._get(path=f"/{self._module_name}/{resource_id}", response_cls=CustomBaseModelResponse) class AsyncStudioCustomModel(AsyncStudioResource, CustomModel): + @deprecated(V3_DEPRECATION_MESSAGE) async def create( self, dataset_id: str, @@ -54,8 +59,10 @@ async def create( ) await self._post(path=f"/{self._module_name}", body=body, response_cls=None) + @deprecated(V3_DEPRECATION_MESSAGE) async def list(self) -> List[CustomBaseModelResponse]: return await self._get(path=f"/{self._module_name}", response_cls=List[CustomBaseModelResponse]) + @deprecated(V3_DEPRECATION_MESSAGE) async def get(self, resource_id: str) -> CustomBaseModelResponse: return await self._get(path=f"/{self._module_name}/{resource_id}", response_cls=CustomBaseModelResponse) diff --git a/ai21/clients/studio/resources/studio_dataset.py b/ai21/clients/studio/resources/studio_dataset.py index 568d9ad8..0a9df9ca 100644 --- a/ai21/clients/studio/resources/studio_dataset.py +++ b/ai21/clients/studio/resources/studio_dataset.py @@ -3,9 +3,11 @@ from ai21.clients.common.dataset_base import Dataset from ai21.clients.studio.resources.studio_resource import StudioResource, AsyncStudioResource from ai21.models import DatasetResponse +from ai21.version_utils import V3_DEPRECATION_MESSAGE, deprecated class StudioDataset(StudioResource, Dataset): + @deprecated(V3_DEPRECATION_MESSAGE) def create( self, file_path: str, @@ -32,14 +34,17 @@ def create( files=files, ) + @deprecated(V3_DEPRECATION_MESSAGE) def list(self) -> List[DatasetResponse]: return self._get(path=f"/{self._module_name}", response_cls=List[DatasetResponse]) + @deprecated(V3_DEPRECATION_MESSAGE) def get(self, dataset_pid: str) -> DatasetResponse: return self._get(path=f"/{self._module_name}/{dataset_pid}", response_cls=DatasetResponse) class AsyncStudioDataset(AsyncStudioResource, Dataset): + @deprecated(V3_DEPRECATION_MESSAGE) async def create( self, file_path: str, @@ -67,8 +72,10 @@ async def create( files=files, ) + @deprecated(V3_DEPRECATION_MESSAGE) async def list(self) -> List[DatasetResponse]: return await self._get(path=f"/{self._module_name}", response_cls=List[DatasetResponse]) + @deprecated(V3_DEPRECATION_MESSAGE) async def get(self, dataset_pid: str) -> DatasetResponse: return await self._get(path=f"/{self._module_name}/{dataset_pid}", response_cls=DatasetResponse) diff --git a/ai21/clients/studio/resources/studio_embed.py b/ai21/clients/studio/resources/studio_embed.py index 5bfa7e69..b6ffa100 100644 --- a/ai21/clients/studio/resources/studio_embed.py +++ b/ai21/clients/studio/resources/studio_embed.py @@ -3,9 +3,11 @@ from ai21.clients.common.embed_base import Embed from ai21.clients.studio.resources.studio_resource import StudioResource, AsyncStudioResource from ai21.models import EmbedType, EmbedResponse +from ai21.version_utils import V3_DEPRECATION_MESSAGE, deprecated class StudioEmbed(StudioResource, Embed): + @deprecated(V3_DEPRECATION_MESSAGE) def create(self, texts: List[str], type: Optional[EmbedType] = None, **kwargs) -> EmbedResponse: body = self._create_body(texts=texts, type=type, **kwargs) @@ -13,6 +15,7 @@ def create(self, texts: List[str], type: Optional[EmbedType] = None, **kwargs) - class AsyncStudioEmbed(AsyncStudioResource, Embed): + @deprecated(V3_DEPRECATION_MESSAGE) async def create(self, texts: List[str], type: Optional[EmbedType] = None, **kwargs) -> EmbedResponse: body = self._create_body(texts=texts, type=type, **kwargs) diff --git a/ai21/clients/studio/resources/studio_gec.py b/ai21/clients/studio/resources/studio_gec.py index 29daa5c4..f2486d58 100644 --- a/ai21/clients/studio/resources/studio_gec.py +++ b/ai21/clients/studio/resources/studio_gec.py @@ -1,9 +1,11 @@ from ai21.clients.common.gec_base import GEC from ai21.clients.studio.resources.studio_resource import StudioResource, AsyncStudioResource from ai21.models import GECResponse +from ai21.version_utils import V3_DEPRECATION_MESSAGE, deprecated class StudioGEC(StudioResource, GEC): + @deprecated(V3_DEPRECATION_MESSAGE) def create(self, text: str, **kwargs) -> GECResponse: body = self._create_body(text=text, **kwargs) @@ -11,6 +13,7 @@ def create(self, text: str, **kwargs) -> GECResponse: class AsyncStudioGEC(AsyncStudioResource, GEC): + @deprecated(V3_DEPRECATION_MESSAGE) async def create(self, text: str, **kwargs) -> GECResponse: body = self._create_body(text=text, **kwargs) diff --git a/ai21/clients/studio/resources/studio_improvements.py b/ai21/clients/studio/resources/studio_improvements.py index 2e09d8a9..f5b8adb4 100644 --- a/ai21/clients/studio/resources/studio_improvements.py +++ b/ai21/clients/studio/resources/studio_improvements.py @@ -3,9 +3,11 @@ from ai21.clients.common.improvements_base import Improvements from ai21.clients.studio.resources.studio_resource import StudioResource, AsyncStudioResource from ai21.models import ImprovementType, ImprovementsResponse +from ai21.version_utils import V3_DEPRECATION_MESSAGE, deprecated class StudioImprovements(StudioResource, Improvements): + @deprecated(V3_DEPRECATION_MESSAGE) def create(self, text: str, types: List[ImprovementType], **kwargs) -> ImprovementsResponse: self._validate_types(types) @@ -15,6 +17,7 @@ def create(self, text: str, types: List[ImprovementType], **kwargs) -> Improveme class AsyncStudioImprovements(AsyncStudioResource, Improvements): + @deprecated(V3_DEPRECATION_MESSAGE) async def create(self, text: str, types: List[ImprovementType], **kwargs) -> ImprovementsResponse: self._validate_types(types) diff --git a/ai21/clients/studio/resources/studio_paraphrase.py b/ai21/clients/studio/resources/studio_paraphrase.py index ee6f3afe..194e378f 100644 --- a/ai21/clients/studio/resources/studio_paraphrase.py +++ b/ai21/clients/studio/resources/studio_paraphrase.py @@ -3,9 +3,11 @@ from ai21.clients.common.paraphrase_base import Paraphrase from ai21.clients.studio.resources.studio_resource import StudioResource, AsyncStudioResource from ai21.models import ParaphraseStyleType, ParaphraseResponse +from ai21.version_utils import V3_DEPRECATION_MESSAGE, deprecated class StudioParaphrase(StudioResource, Paraphrase): + @deprecated(V3_DEPRECATION_MESSAGE) def create( self, text: str, @@ -27,6 +29,7 @@ def create( class AsyncStudioParaphrase(AsyncStudioResource, Paraphrase): + @deprecated(V3_DEPRECATION_MESSAGE) async def create( self, text: str, diff --git a/ai21/clients/studio/resources/studio_segmentation.py b/ai21/clients/studio/resources/studio_segmentation.py index 80ed5639..7bcd0e6f 100644 --- a/ai21/clients/studio/resources/studio_segmentation.py +++ b/ai21/clients/studio/resources/studio_segmentation.py @@ -1,9 +1,11 @@ from ai21.clients.common.segmentation_base import Segmentation from ai21.clients.studio.resources.studio_resource import StudioResource, AsyncStudioResource from ai21.models import DocumentType, SegmentationResponse +from ai21.version_utils import V3_DEPRECATION_MESSAGE, deprecated class StudioSegmentation(StudioResource, Segmentation): + @deprecated(V3_DEPRECATION_MESSAGE) def create(self, source: str, source_type: DocumentType, **kwargs) -> SegmentationResponse: body = self._create_body(source=source, source_type=source_type.value, **kwargs) @@ -11,6 +13,7 @@ def create(self, source: str, source_type: DocumentType, **kwargs) -> Segmentati class AsyncStudioSegmentation(AsyncStudioResource, Segmentation): + @deprecated(V3_DEPRECATION_MESSAGE) async def create(self, source: str, source_type: DocumentType, **kwargs) -> SegmentationResponse: body = self._create_body(source=source, source_type=source_type.value, **kwargs) diff --git a/ai21/clients/studio/resources/studio_summarize.py b/ai21/clients/studio/resources/studio_summarize.py index 47a040e0..b8a86cff 100644 --- a/ai21/clients/studio/resources/studio_summarize.py +++ b/ai21/clients/studio/resources/studio_summarize.py @@ -3,9 +3,11 @@ from ai21.clients.common.summarize_base import Summarize from ai21.clients.studio.resources.studio_resource import StudioResource, AsyncStudioResource from ai21.models import SummarizeResponse, SummaryMethod +from ai21.version_utils import V3_DEPRECATION_MESSAGE, deprecated class StudioSummarize(StudioResource, Summarize): + @deprecated(V3_DEPRECATION_MESSAGE) def create( self, source: str, @@ -27,6 +29,7 @@ def create( class AsyncStudioSummarize(AsyncStudioResource, Summarize): + @deprecated(V3_DEPRECATION_MESSAGE) async def create( self, source: str, diff --git a/ai21/clients/studio/resources/studio_summarize_by_segment.py b/ai21/clients/studio/resources/studio_summarize_by_segment.py index 525db522..0c47203a 100644 --- a/ai21/clients/studio/resources/studio_summarize_by_segment.py +++ b/ai21/clients/studio/resources/studio_summarize_by_segment.py @@ -3,9 +3,11 @@ from ai21.clients.common.summarize_by_segment_base import SummarizeBySegment from ai21.clients.studio.resources.studio_resource import StudioResource, AsyncStudioResource from ai21.models import SummarizeBySegmentResponse, DocumentType +from ai21.version_utils import V3_DEPRECATION_MESSAGE, deprecated class StudioSummarizeBySegment(StudioResource, SummarizeBySegment): + @deprecated(V3_DEPRECATION_MESSAGE) def create( self, source: str, @@ -25,6 +27,7 @@ def create( class AsyncStudioSummarizeBySegment(AsyncStudioResource, SummarizeBySegment): + @deprecated(V3_DEPRECATION_MESSAGE) async def create( self, source: str, diff --git a/ai21/version_utils.py b/ai21/version_utils.py new file mode 100644 index 00000000..36f4da3f --- /dev/null +++ b/ai21/version_utils.py @@ -0,0 +1,16 @@ +import warnings +from functools import wraps + +V3_DEPRECATION_MESSAGE = "This model is not supported anymore - Please upgrade to v3.0.0" + + +def deprecated(message): + def decorator(func): + @wraps(func) + def wrapper(*args, **kwargs): + warnings.warn(message, category=DeprecationWarning, stacklevel=2) + return func(*args, **kwargs) + + return wrapper + + return decorator