Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adding depracation warning to all TSMs, custom models and datasets #223

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ai21/clients/sagemaker/resources/sagemaker_answer.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -17,6 +19,7 @@ def create(


class AsyncSageMakerAnswer(AsyncSageMakerResource, Answer):
@deprecated(V3_DEPRECATION_MESSAGE)
async def create(
self,
context: str,
Expand Down
3 changes: 3 additions & 0 deletions ai21/clients/sagemaker/resources/sagemaker_gec.py
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions ai21/clients/sagemaker/resources/sagemaker_paraphrase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -27,6 +29,7 @@ def create(


class AsyncSageMakerParaphrase(AsyncSageMakerResource, Paraphrase):
@deprecated(V3_DEPRECATION_MESSAGE)
async def create(
self,
text: str,
Expand Down
3 changes: 3 additions & 0 deletions ai21/clients/sagemaker/resources/sagemaker_summarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -30,6 +32,7 @@ def create(


class AsyncSageMakerSummarize(AsyncSageMakerResource, Summarize):
@deprecated(V3_DEPRECATION_MESSAGE)
async def create(
self,
source: str,
Expand Down
3 changes: 3 additions & 0 deletions ai21/clients/studio/resources/studio_answer.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -16,6 +18,7 @@ def create(


class AsyncStudioAnswer(AsyncStudioResource, Answer):
@deprecated(V3_DEPRECATION_MESSAGE)
async def create(
self,
context: str,
Expand Down
7 changes: 7 additions & 0 deletions ai21/clients/studio/resources/studio_custom_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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)
7 changes: 7 additions & 0 deletions ai21/clients/studio/resources/studio_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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)
3 changes: 3 additions & 0 deletions ai21/clients/studio/resources/studio_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
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)

return self._post(path=f"/{self._module_name}", body=body, response_cls=EmbedResponse)


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)

Expand Down
3 changes: 3 additions & 0 deletions ai21/clients/studio/resources/studio_gec.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
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)

return self._post(path=f"/{self._module_name}", body=body, response_cls=GECResponse)


class AsyncStudioGEC(AsyncStudioResource, GEC):
@deprecated(V3_DEPRECATION_MESSAGE)
async def create(self, text: str, **kwargs) -> GECResponse:
body = self._create_body(text=text, **kwargs)

Expand Down
3 changes: 3 additions & 0 deletions ai21/clients/studio/resources/studio_improvements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions ai21/clients/studio/resources/studio_paraphrase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -27,6 +29,7 @@ def create(


class AsyncStudioParaphrase(AsyncStudioResource, Paraphrase):
@deprecated(V3_DEPRECATION_MESSAGE)
async def create(
self,
text: str,
Expand Down
3 changes: 3 additions & 0 deletions ai21/clients/studio/resources/studio_segmentation.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
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)

return self._post(path=f"/{self._module_name}", body=body, response_cls=SegmentationResponse)


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)

Expand Down
3 changes: 3 additions & 0 deletions ai21/clients/studio/resources/studio_summarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -27,6 +29,7 @@ def create(


class AsyncStudioSummarize(AsyncStudioResource, Summarize):
@deprecated(V3_DEPRECATION_MESSAGE)
async def create(
self,
source: str,
Expand Down
3 changes: 3 additions & 0 deletions ai21/clients/studio/resources/studio_summarize_by_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -25,6 +27,7 @@ def create(


class AsyncStudioSummarizeBySegment(AsyncStudioResource, SummarizeBySegment):
@deprecated(V3_DEPRECATION_MESSAGE)
async def create(
self,
source: str,
Expand Down
16 changes: 16 additions & 0 deletions ai21/version_utils.py
Original file line number Diff line number Diff line change
@@ -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
Loading