def sum_up(text: str, max_length: int = 144, stop_at: str = ". ") -> str:
    """Summarize text to fit within max_length, ending at last complete sentence."""
    summary = (text + os.linesep).splitlines()[0].strip()
    if len(summary) <= max_length:
        return summary
    if stop_at and stop_at in summary[:max_length]:
        return summary[:summary.rfind(stop_at, 0, max_length)] + stop_at.strip()
    return summary[:max_length].strip()
Summarize text to fit within max_length, ending at last complete sentence.
winpython/utils.py