Skip to main content

Summarize

Our summarize-endpoint can be used to generate summaries for longer texts.

Code Example

import os
from aleph_alpha_client import Client, Document, SummarizationRequest
# If you are using a Windows machine, you must install the python-dotenv package and run the two below lines as well.
# from dotenv import load_dotenv
# load_dotenv()

client = Client(token=os.getenv("AA_TOKEN"))
document_text = "The gray wolf (Canis lupus) is a species of placental mammal of the carnivore order. The earliest fossil record dates back eight hundred thousand years. Wolves are native to North America and Eurasia, where they were once widely distributed and abundant. Today, they inhabit only a very limited portion of their former territory."
request = SummarizationRequest(document=Document.from_text(document_text))
response = client.summarize(request=request)
summary = response.summary

print(f"""Document: {document_text}
Summary: {summary}""")
# prints:
# Document: [...]
# Summary: Wolves are native to North America and Eurasia, but are now only found in a very limited portion of their former territory.

If you need more information on the parameters you can use, please checkout our HTTP API.