Skip to content

Commit

Permalink
Deprecate Q&A and Summarization client methods
Browse files Browse the repository at this point in the history
Also deprecates all related request/response classes.

Provides warning logs at call sites.
  • Loading branch information
benbrandt committed Sep 25, 2023
1 parent e90fa62 commit 8de051e
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 3.5.0

- Deprecation of `qa` and `summarization` methods on `Client` and `AsyncClient`. New methods of processing these tasks will be released before they are removed in the next major version.

## 3.4.2

- Full release for exporting type hints
Expand Down
41 changes: 37 additions & 4 deletions aleph_alpha_client/aleph_alpha_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from tokenizers import Tokenizer # type: ignore
from types import TracebackType
from typing import (
Expand Down Expand Up @@ -473,7 +474,10 @@ def evaluate(
return EvaluationResponse.from_json(response)

def qa(self, request: QaRequest) -> QaResponse:
"""Answers a question about documents.
"""DEPRECATED: `qa` is deprecated and will be removed in the next major release. New
methods of processing Q&A tasks will be provided before this is removed.
Answers a question about documents.
Parameters:
request (QaRequest, required):
Expand All @@ -486,14 +490,22 @@ def qa(self, request: QaRequest) -> QaResponse:
)
>>> response = client.qa(request)
"""
warnings.warn(
"qa is deprecated and will be removed in the next major release. New methods of processing Q&A tasks will be provided before this is removed.",
category=DeprecationWarning,
stacklevel=2,
)
response = self._post_request("qa", request)
return QaResponse.from_json(response)

def summarize(
self,
request: SummarizationRequest,
) -> SummarizationResponse:
"""Summarizes a document.
"""DEPRECATED: `summarize` is deprecated and will be removed in the next major release. New
methods of processing Summarization tasks will be provided before this is removed.
Summarizes a document.
Parameters:
request (SummarizationRequest, required):
Expand All @@ -505,6 +517,11 @@ def summarize(
)
>>> response = client.summarize(request, model="luminous-extended")
"""
warnings.warn(
"summarize is deprecated and will be removed in the next major release. New methods of processing Q&A tasks will be provided before this is removed.",
category=DeprecationWarning,
stacklevel=2,
)
response = self._post_request(
"summarize",
request,
Expand Down Expand Up @@ -981,7 +998,10 @@ async def evaluate(
return EvaluationResponse.from_json(response)

async def qa(self, request: QaRequest) -> QaResponse:
"""Answers a question about documents.
"""DEPRECATED: `qa` is deprecated and will be removed in the next major release. New
methods of processing Q&A tasks will be provided before this is removed.
Answers a question about documents.
Parameters:
request (QaRequest, required):
Expand All @@ -994,14 +1014,22 @@ async def qa(self, request: QaRequest) -> QaResponse:
)
>>> response = await client.qa(request, model="luminous-extended")
"""
warnings.warn(
"qa is deprecated and will be removed in the next major release. New methods of processing Q&A tasks will be provided before this is removed.",
category=DeprecationWarning,
stacklevel=2,
)
response = await self._post_request("qa", request)
return QaResponse.from_json(response)

async def summarize(
self,
request: SummarizationRequest,
) -> SummarizationResponse:
"""Summarizes a document.
"""DEPRECATED: `summarize` is deprecated and will be removed in the next major release. New
methods of processing Summarization tasks will be provided before this is removed.
Summarizes a document.
Parameters:
request (SummarizationRequest, required):
Expand All @@ -1012,6 +1040,11 @@ async def summarize(
)
>>> response = await client.summarize(request, model="luminous-extended")
"""
warnings.warn(
"summarize is deprecated and will be removed in the next major release. New methods of processing Q&A tasks will be provided before this is removed.",
category=DeprecationWarning,
stacklevel=2,
)
response = await self._post_request(
"summarize",
request,
Expand Down
12 changes: 11 additions & 1 deletion aleph_alpha_client/qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@


class QaRequest(NamedTuple):
"""
"""DEPRECATED: `QaRequest` is deprecated and will be removed in the next major release. New
methods of processing Q&A tasks will be provided before this is removed.
Answers a question about a prompt.
Parameters:
Expand Down Expand Up @@ -39,12 +41,20 @@ def to_json(self) -> Dict[str, Any]:


class QaAnswer(NamedTuple):
"""DEPRECATED: `QaAnswer` is deprecated and will be removed in the next major release. New
methods of processing Q&A tasks will be provided before this is removed.
"""

answer: str
score: float
evidence: str


class QaResponse(NamedTuple):
"""DEPRECATED: `QaResponse` is deprecated and will be removed in the next major release. New
methods of processing Q&A tasks will be provided before this is removed.
"""

answers: Sequence[QaAnswer]

@staticmethod
Expand Down
8 changes: 7 additions & 1 deletion aleph_alpha_client/summarization.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@


class SummarizationRequest(NamedTuple):
"""
"""DEPRECATED: `SummarizationRequest` is deprecated and will be removed in the next major release. New
methods of processing Summarization tasks will be provided before this is removed.
Summarizes a document.
Parameters:
Expand Down Expand Up @@ -40,6 +42,10 @@ def to_json(self) -> Dict[str, Any]:


class SummarizationResponse(NamedTuple):
"""DEPRECATED: `SummarizationResponse` is deprecated and will be removed in the next major release. New
methods of processing Summarization tasks will be provided before this is removed.
"""

summary: str

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion aleph_alpha_client/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "3.4.2"
__version__ = "3.5.0"

0 comments on commit 8de051e

Please sign in to comment.