Spaces:
Build error
Build error
File size: 2,255 Bytes
64772a4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
from dataclasses import asdict, dataclass
from typing import Any, Dict, Mapping, Sequence
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"])
|