Skip to main content

A flexible text summarization service supporting multiple AI providers

Project description

Asta Summarizer Service

A flexible text summarization service that supports multiple AI providers including OpenAI-compatible APIs and HuggingFace Inference endpoints with a consistent tone used for Asta.

Features

  • Multiple Provider Support: Works with both OpenAI-compatible APIs and HuggingFace Inference clients
  • Flexible Summarization Types: Support for different summarization styles (default, thread titles, etc.)
  • Customizable Length: Configure summary length to meet your needs

Installation

pip install asta-summarizer

Quick Start

Using with OpenAI-compatible API

import asyncio
from asta_summarizer import SummarizerService, SummarizationType

async def main():
    # Initialize with base_url for OpenAI-compatible API
    service = SummarizerService(
        base_url="https://your-api-endpoint.com/v1",
        model="your-model-name",
        api_key="your-api-key"  # or set SUMMARIZER_API_KEY environment variable
    )

    text = "Your long text to summarize..."

    summary = await service.summarize(
        text=text,
        length=100,
        summarization_type=SummarizationType.DEFAULT
    )

    print(summary)

if __name__ == "__main__":
    asyncio.run(main())

Using with HuggingFace Provider

import asyncio
from asta_summarizer import SummarizerService, SummarizationType

async def main():
    # Initialize with provider for HuggingFace Inference
    service = SummarizerService(
        provider="huggingface",  # or other supported providers
        model="your-model-name",
        api_key="your-hf-token"  # or set SUMMARIZER_API_KEY environment variable
    )

    text = "Your long text to summarize..."

    summary = await service.summarize(
        text=text,
        length=200,
        summarization_type=SummarizationType.THREAD_TITLE
    )

    print(summary)

if __name__ == "__main__":
    asyncio.run(main())

Configuration

Initialization Parameters

  • model (required): The model name to use for summarization
  • base_url (optional): Base URL for OpenAI-compatible APIs (mutually exclusive with provider)
  • provider (optional): Provider name for HuggingFace Inference (mutually exclusive with base_url)
  • api_key (optional): API key for authentication (defaults to SUMMARIZER_API_KEY environment variable)

Summarization Types

The service supports different summarization styles via the SummarizationType enum:

  • SummarizationType.DEFAULT: Standard summarization. Pass in your own prompt alongside the text to summarize in the text field.
  • SummarizationType.THREAD_TITLE: Optimized for creating thread titles

Environment Variables

Set your API key as an environment variable:

export SUMMARIZER_API_KEY="your-api-key-here"

Development

Installing Dependencies

For development work:

# Install package in editable mode with development dependencies
pip install -e ".[dev]"

Or install dependencies manually:

# Core dependencies
pip install huggingface-hub>=0.20.0 openai>=1.0.0

# Development dependencies
pip install pytest>=7.0.0 pytest-asyncio>=0.21.0 black>=23.0.0 isort>=5.12.0 mypy>=1.0.0

Code Formatting

black .
isort .

Type Checking

mypy asta_summarizer/

Publication

You can publish a new version from your branch before merging to main, or from main after merging.

Edit the version.txt file with the new version, then run

export AI2_NORA_PYPI_TOKEN=<SECRET IN NORA VAULT>
make publish

This will publish the summarizer with the version number contained in version.txt

License

MIT License - see LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asta_summarizer-0.1.1.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

asta_summarizer-0.1.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file asta_summarizer-0.1.1.tar.gz.

File metadata

  • Download URL: asta_summarizer-0.1.1.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for asta_summarizer-0.1.1.tar.gz
Algorithm Hash digest
SHA256 aa733b05a712df4ecaca3e33961ae00a5af88dd0e82c57bc6cae2681dd066f5e
MD5 de0ad1f3693d7734ed60717dd9a92cef
BLAKE2b-256 3b6b43d8511f19adb3d466abde95904cc8774d0260b592f6b3c66a4511d4c158

See more details on using hashes here.

File details

Details for the file asta_summarizer-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for asta_summarizer-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 275d5d17a3f8cb8511c08f3631e448819ef3ef478668447b17a902e37eeedd6b
MD5 985d9b07e04e28db621a1bb5299681e7
BLAKE2b-256 ef85b5c896f6d8766a1e74b4a40be18c873c35e93553fc35e12034ca7dfbe88e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page