diff --git a/Changelog.md b/Changelog.md index 1d49a27..8db7c30 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,9 @@ # Changelog +## 9.0.0 + +- Remove deprecated QA and Summarization functionality + ## 8.1.0 ### Python support diff --git a/aleph_alpha_client/__init__.py b/aleph_alpha_client/__init__.py index 665a901..30c1a75 100644 --- a/aleph_alpha_client/__init__.py +++ b/aleph_alpha_client/__init__.py @@ -46,8 +46,6 @@ TokenPromptItemExplanation, TokenScore, ) -from .qa import QaRequest, QaResponse -from .summarization import SummarizationRequest, SummarizationResponse from .tokenization import TokenizationRequest, TokenizationResponse from .utils import load_base64_from_file, load_base64_from_url from .version import __version__ @@ -83,14 +81,10 @@ "Prompt", "PromptTemplate", "PromptGranularity", - "QaRequest", - "QaResponse", "QuotaError", "SemanticEmbeddingRequest", "SemanticEmbeddingResponse", "SemanticRepresentation", - "SummarizationRequest", - "SummarizationResponse", "TargetGranularity", "TargetPromptItemExplanation", "TargetScore", diff --git a/aleph_alpha_client/aleph_alpha_client.py b/aleph_alpha_client/aleph_alpha_client.py index b375d05..8d31ceb 100644 --- a/aleph_alpha_client/aleph_alpha_client.py +++ b/aleph_alpha_client/aleph_alpha_client.py @@ -29,8 +29,7 @@ ExplanationRequest, ExplanationResponse, ) -from aleph_alpha_client.summarization import SummarizationRequest, SummarizationResponse -from aleph_alpha_client.qa import QaRequest, QaResponse + from aleph_alpha_client.completion import ( CompletionRequest, CompletionResponse, @@ -114,8 +113,6 @@ def _check_api_version(version_str: str): SemanticEmbeddingRequest, InstructableEmbeddingRequest, BatchSemanticEmbeddingRequest, - QaRequest, - SummarizationRequest, ExplanationRequest, ExplanationRequest, ] @@ -604,61 +601,6 @@ def evaluate( ) return EvaluationResponse.from_json(response) - def qa(self, request: QaRequest) -> QaResponse: - """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): - Parameters for the qa request. - - Examples: - >>> request = QaRequest( - query="Who likes pizza?", - documents=[Document.from_text("Andreas likes pizza.")], - ) - >>> 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: - """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): - Parameters for the requested summarization. - - Examples: - >>> request = SummarizationRequest( - document=Document.from_text("Andreas likes pizza."), - ) - >>> 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, - ) - return SummarizationResponse.from_json(response) - def explain( self, request: ExplanationRequest, @@ -1350,60 +1292,6 @@ async def evaluate( ) return EvaluationResponse.from_json(response) - async def qa(self, request: QaRequest) -> QaResponse: - """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): - Parameters for the qa request. - - Examples: - >>> request = QaRequest( - query="Who likes pizza?", - documents=[Document.from_text("Andreas likes pizza.")], - ) - >>> 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: - """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): - Parameters for the requested summarization. - Examples: - >>> request = SummarizationRequest( - document=Document.from_text("Andreas likes pizza."), - ) - >>> 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, - ) - return SummarizationResponse.from_json(response) - async def explain( self, request: ExplanationRequest, diff --git a/aleph_alpha_client/qa.py b/aleph_alpha_client/qa.py deleted file mode 100644 index f51a386..0000000 --- a/aleph_alpha_client/qa.py +++ /dev/null @@ -1,76 +0,0 @@ -from dataclasses import asdict, dataclass -from typing import Any, Mapping, Optional, Sequence - -from aleph_alpha_client.document import Document - - -@dataclass(frozen=True) -class QaRequest: - """DEPRECATED: `QaRequest` is deprecated and will be removed in the future. New - methods of processing Q&A tasks will be provided before this is removed. - - Answers a question about a prompt. - - Parameters: - query (str, required): - The question to be answered about the documents by the model. - - documents (List[Document], required): - A list of documents. This can be either docx documents or text/image prompts. - - max_answers (int, default None): - The maximum number of answers. - - Examples: - >>> request = QaRequest( - query = "What is a computer program?", - documents = [document] - ) - """ - - query: str - documents: Sequence[Document] - max_answers: Optional[int] = None - - def to_json(self) -> Mapping[str, Any]: - payload = { - **self._asdict(), - "documents": [ - document._to_serializable_document() for document in self.documents - ], - } - if self.max_answers is None: - del payload["max_answers"] - return payload - - def _asdict(self) -> Mapping[str, Any]: - return asdict(self) - - -@dataclass(frozen=True) -class QaAnswer: - """DEPRECATED: `QaAnswer` is deprecated and will be removed in the future. New - methods of processing Q&A tasks will be provided before this is removed. - """ - - answer: str - score: float - evidence: str - - -@dataclass(frozen=True) -class QaResponse: - """DEPRECATED: `QaResponse` is deprecated and will be removed in the future. New - methods of processing Q&A tasks will be provided before this is removed. - """ - - answers: Sequence[QaAnswer] - - @staticmethod - def from_json(json: Mapping[str, Any]) -> "QaResponse": - return QaResponse( - answers=[ - QaAnswer(item["answer"], item["score"], item["evidence"]) - for item in json["answers"] - ], - ) diff --git a/aleph_alpha_client/summarization.py b/aleph_alpha_client/summarization.py deleted file mode 100644 index e958b29..0000000 --- a/aleph_alpha_client/summarization.py +++ /dev/null @@ -1,57 +0,0 @@ -from dataclasses import asdict, dataclass -from typing import Any, Mapping - -from aleph_alpha_client.document import Document - - -@dataclass(frozen=True) -class SummarizationRequest: - """DEPRECATED: `SummarizationRequest` is deprecated and will be removed in the future. New - methods of processing Summarization tasks will be provided before this is removed. - - Summarizes a document. - - Parameters: - document (Document, required): - A single document. This can be one of the following formats: - - - Docx: A base64 encoded Docx file - - Text: A string of text - - Prompt: A multimodal prompt, as is used in our other tasks like Completion - - Documents of types Docx and Text are usually preferred, and will have optimizations (such as chunking) applied to work better with the respective task that is being run. - - Prompt documents are assumed to be used for advanced use cases, and will be left as-is. - - disable_optimizations (bool, default False) - We continually research optimal ways to work with our models. By default, we apply these optimizations to both your query, documents, and answers for you. - Our goal is to improve your results while using our API. - But you can always pass `disable_optimizations: true` and we will leave your document and summary untouched. - - Examples: - >>> docx_file = "./tests/sample.docx" - >>> document = Document.from_docx_file(docx_file) - >>> request = SummarizationRequest(document) - """ - - document: Document - disable_optimizations: bool = False - - def to_json(self) -> Mapping[str, Any]: - return {**self._asdict(), "document": self.document._to_serializable_document()} - - def _asdict(self) -> Mapping[str, Any]: - return asdict(self) - - -@dataclass(frozen=True) -class SummarizationResponse: - """DEPRECATED: `SummarizationResponse` is deprecated and will be removed in the future. New - methods of processing Summarization tasks will be provided before this is removed. - """ - - summary: str - - @classmethod - def from_json(cls, json: Mapping[str, Any]) -> "SummarizationResponse": - return cls(summary=json["summary"]) diff --git a/pyproject.toml b/pyproject.toml index 5c22465..e5e4c96 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "aleph-alpha-client" -version = "8.1.0" +version = "9.0.0" description = "python client to interact with Aleph Alpha api endpoints" authors = ["Aleph Alpha "] license = "MIT" diff --git a/tests/test_qa.py b/tests/test_qa.py deleted file mode 100644 index 88cff6f..0000000 --- a/tests/test_qa.py +++ /dev/null @@ -1,74 +0,0 @@ -import pytest -from aleph_alpha_client.aleph_alpha_client import AsyncClient, Client -from aleph_alpha_client.document import Document -from aleph_alpha_client.prompt import Prompt -from aleph_alpha_client.qa import QaRequest - - -# AsyncClient - -SKIP_REASON = ( - "skipping as qa endpoint is deprecated and required model is no longer available" -) - - -@pytest.mark.skip(reason=SKIP_REASON) -async def test_can_qa_with_async_client(async_client: AsyncClient): - request = QaRequest( - query="Who likes pizza?", - documents=[Document.from_text("Andreas likes pizza.")], - ) - response = await async_client.qa(request) - assert len(response.answers) == 1 - assert response.answers[0].score > 0.0 - - -# Client - - -@pytest.mark.skip(reason=SKIP_REASON) -def test_qa_from_text(sync_client: Client): - # when posting a QA request with a QaRequest object - request = QaRequest( - query="Who likes pizza?", - documents=[Document.from_text("Andreas likes pizza.")], - ) - - response = sync_client.qa(request) - - # the response should exist and be in the form of a named tuple class - assert len(response.answers) == 1 - assert response.answers[0].score > 0.5 - - -@pytest.mark.skip(reason=SKIP_REASON) -def test_qa_no_answer_found(sync_client: Client): - # when posting a QA request with a QaRequest object - request = QaRequest( - query="Who likes pizza?", - documents=[], - ) - - response = sync_client.qa(request) - - # the response should exist and be in the form of a named tuple class - assert len(response.answers) == 0 - - -@pytest.mark.skip(reason=SKIP_REASON) -def test_prompt(sync_client: Client): - # when posting an illegal request - request = QaRequest( - query="Who likes pizza?", - documents=[ - Document.from_prompt(Prompt.from_text("Andreas likes pizza.")) - for _ in range(20) - ], - ) - - # then we expect an exception tue to a bad request response from the API - response = sync_client.qa(request) - - # The response should exist in the form of a json dict - assert len(response.answers) == 20 - assert response.answers[0].score > 0.5 diff --git a/tests/test_summarize.py b/tests/test_summarize.py deleted file mode 100644 index db69e5e..0000000 --- a/tests/test_summarize.py +++ /dev/null @@ -1,49 +0,0 @@ -import pytest -from aleph_alpha_client import Document, SummarizationRequest -from aleph_alpha_client.aleph_alpha_client import AsyncClient, Client - - -# AsyncClient - - -SKIP_REASON = "skipping as summarization endpoint is deprecated and required model is no longer available" - - -@pytest.mark.skip(reason=SKIP_REASON) -@pytest.mark.system_test -async def test_can_summarize_with_async_client(async_client: AsyncClient): - request = SummarizationRequest( - document=Document.from_text("Andreas likes pizza."), - ) - - response = await async_client.summarize(request) - assert response.summary is not None - - -# Client - - -@pytest.mark.skip(reason=SKIP_REASON) -@pytest.mark.system_test -def test_summarize(sync_client: Client): - # when posting a Summarization request - request = SummarizationRequest( - document=Document.from_prompt(["Andreas likes pizza."]), - ) - - response = sync_client.summarize(request) - - # the response should exist and be in the form of a named tuple class - assert response.summary is not None - - -@pytest.mark.skip(reason=SKIP_REASON) -@pytest.mark.system_test -def test_text(sync_client: Client): - request = SummarizationRequest( - document=Document.from_text("Andreas likes pizza."), - ) - - response = sync_client.summarize(request) - - assert response.summary is not None