def truncate_sentence(text, max_chars, break_words=False, padding=<NUM_LIT:0>):
if break_words:<EOL><INDENT>return text[:-abs(max_chars - len(text)) - padding]<EOL><DEDENT>words = []<EOL>for word in text.split():<EOL><INDENT>predicted_len = (<EOL>sum(map(len, words)) +  <EOL>len(word) +  <EOL>len(words) - <NUM_LIT:1> +  <EOL>padding)<EOL>if predicted_len >= max_chars:<EOL><INDENT>break<EOL><DEDENT>words.append(word)<EOL><DEDENT>return '<STR_LIT:U+0020>'.join(words)<EOL>
Truncates a sentence.

    :param max_chars: The maximum characters of truncated sentence.
    :param break_words: If you wish to truncate given sentence strictly even
                        if it breaks a word, set it to ``True``. It defaults
                        to ``False`` which means truncating given sentence
                        shorter but never breaking words.
    :param padding: The padding size for truncating. It is usually used to
                    keep spaces for some ending characters such as ``"..."``.
    :return: The truncated sentence.