Skip to main content

LLM based context aware text summarizer

Project description

azure-llm-summarizer

A lightweight Python library for summarizing text using Azure OpenAI, with built-in token counting for both input and output — no extra dependencies beyond openai.

Installation

pip install azure-llm-summarizer

Quick Start

from llm_summarizer import AzureSummarizer

summarizer = AzureSummarizer(
    api_key="<your-azure-api-key>",
    azure_endpoint="https://<your-resource>.openai.azure.com",
    deployment_name="gpt-4o-mini",   # your deployed model name
)

result = summarizer.summarize(
    text="Your long document or passage goes here...",
    summary_type="medium",    # "short" | "medium" | "detailed"
    tone="neutral",           # "neutral" | "formal" | "casual"
    focus_area="general",     # "general" | "technical insights" | "financial" ...
    output_format="text",     # "text" | "bullets" | "json"
)

print(result.summary)          # the summary
print(result.input_tokens)     # token count of the original passage
print(result.output_tokens)    # token count of the summary
print(result)                  # summary + token counts in one print

Example Output

Generative AI (GenAI) refers to AI systems that create new content by learning
from large datasets, using architectures like LLMs and diffusion models...

[Tokens — Input: 312 | Summary: 47]

API Reference

AzureSummarizer(azure_endpoint, api_key, api_version, deployment_name)

Parameter Type Default Description
azure_endpoint str env AZURE_OPENAI_ENDPOINT Azure resource endpoint
api_key str env AZURE_OPENAI_API_KEY Azure API key
api_version str "2024-02-15-preview" API version
deployment_name str "gi-local-gpt-5-mini" Deployed model name

.summarize(text, summary_type, tone, focus_area, output_format) → SummaryResult

Parameter Options Default
summary_type "short", "medium", "detailed" "medium"
tone "neutral", "formal", "casual" "neutral"
focus_area any string "general"
output_format "text", "bullets", "json" "text"

SummaryResult

Attribute Type Description
summary str The generated summary
input_tokens int Estimated tokens in the original text
output_tokens int Estimated tokens in the summary

Standalone token counter

from llm_summarizer import count_tokens

count_tokens("Hello, world!")  # → 4

Environment Variables

You can skip passing credentials directly and use env vars instead:

export AZURE_OPENAI_ENDPOINT="https://<resource>.openai.azure.com"
export AZURE_OPENAI_API_KEY="<your-key>"

Publishing to PyPI

pip install build twine
python -m build
twine upload dist/*

License

MIT

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

text_summarizer_gi-0.1.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

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

text_summarizer_gi-0.1.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file text_summarizer_gi-0.1.0.tar.gz.

File metadata

  • Download URL: text_summarizer_gi-0.1.0.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for text_summarizer_gi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 024689de11fe3e7496ebb24dfab9baa2c41bf2f034747d53583c3b36f97e2874
MD5 9c669f058a68ee30e35c7483acbd74bb
BLAKE2b-256 1d84ebf3c658e15176bc1019aeeb0fcb8a0fb2b69caabef270a6703d62006e41

See more details on using hashes here.

File details

Details for the file text_summarizer_gi-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for text_summarizer_gi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 21935ad595608e55dca3d57f5672ce3b5d33bd126c215419b40fc0ac4aba8650
MD5 c3a14da2e73414a42cf330638392806f
BLAKE2b-256 faefee902869065147ba80b196d7248572ce2e4efea79fa8a6c14bc9f80239ad

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