AI-powered Markdown summarizer that preserves structure and code blocks
Project description
Markdown Summarizer
An AI-powered tool that reduces the token size of Markdown documents while preserving their essential structure, code blocks, and meaning. Designed to help fit documentation into AI context windows without losing critical information.
Features
- Token Reduction: Intelligently reduces document size
- Preserves markdown heading hierarchy
- Protects code blocks and technical details
- Bottom-up concurrent processing
- Real-time progress updates
- Streaming API
- Multiple AI provider support
- Token usage tracking and reporting
Usage
from md_summarizer import (
MarkdownSummarizer,
ProgressStatus
)
# Basic usage
summarizer = MarkdownSummarizer()
result = await summarizer.summarize(content)
# Check token usage
usage = summarizer.agent.usage
print(f"Input tokens: {usage.request_tokens}")
print(f"Output tokens: {usage.response_tokens}")
print(f"Reduction: {(1 - usage.response_tokens/usage.request_tokens):.1%}")
# Streaming updates
async for update in summarizer.stream(content):
if update.status == ProgressStatus.STARTING:
print(f"Processing {update.total_sections} sections...")
elif update.status == ProgressStatus.SECTION_COMPLETE:
print(f"Completed section: {update.section_title}")
elif update.status == ProgressStatus.COMPLETE:
print("Done!")
print(update.content)
# Show token usage after completion
usage = summarizer.agent.usage
print("\nToken Usage:")
print(f"Input tokens: {usage.request_tokens}")
print(f"Output tokens: {usage.response_tokens}")
print(f"Reduction: {(1 - usage.response_tokens/usage.request_tokens):.1%}")
# Progress update types:
# - ProgressStatus.STARTING: total_sections count
# - ProgressStatus.SECTION_COMPLETE: section_title of completed section
# - ProgressStatus.COMPLETE: final content
# - ProgressStatus.ERROR: error details if something fails
# Customize prompts
summarizer.system_prompt = "Your custom system prompt"
summarizer.user_prompt = "Your custom user prompt"
Example output:
Status: ProgressStatus.STARTING, Total Sections: 4
Status: ProgressStatus.SECTION_COMPLETE, Section: Subsection 2.1
Status: ProgressStatus.SECTION_COMPLETE, Section: Section 1
Status: ProgressStatus.SECTION_COMPLETE, Section: Section 2
Status: ProgressStatus.SECTION_COMPLETE, Section: Test Document
Status: ProgressStatus.COMPLETE
Token Usage:
Input tokens: 1250
Output tokens: 450
Reduction: 64.0%
Installation
Install from PyPI:
pip install md-summarizer
Or install from source:
git clone https://github.com/celtiberi/md-summarizer.git
cd md-summarizer
pip install -e .
Configuration
Set environment variables or use .env file:
OPENAI_API_KEY=your-key
MODEL=gpt-3.5-turbo
PROVIDER=openai
LOG_LEVEL=INFO
How it Works
- Parses markdown into hierarchical sections
- Processes sections bottom-up (children before parents)
- Preserves heading levels and structure
- Provides real-time progress updates
- Combines processed sections into final document
Development
# Install development dependencies
pip install -e ".[test]"
# Run tests
make test
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file md_summarizer-0.1.66.tar.gz.
File metadata
- Download URL: md_summarizer-0.1.66.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb15d37eb310b531ab26840db53fd47fed1366a3c719ff500ef36035e7c9e22a
|
|
| MD5 |
14d77bfe81c4e8920b040466b72705c8
|
|
| BLAKE2b-256 |
064eb1f4507c0b221fb3511de30dc2324169b7f20e1399b61800051cf8258226
|
File details
Details for the file md_summarizer-0.1.66-py3-none-any.whl.
File metadata
- Download URL: md_summarizer-0.1.66-py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9a4dfb2ca13b82e950bd6f822a596e8d819d3f3e7d16a559db3a230eff268ad
|
|
| MD5 |
002c510f3bac0c196be9604954d56f46
|
|
| BLAKE2b-256 |
5f9802bbff553a5aa04bb6f265b585d15a4a48c49bb590daf0363b8228caead6
|