Last active
November 29, 2023 17:59
-
-
Save zoltanctoth/6f0f69fa00adc086d47bbc95ea4a43e9 to your computer and use it in GitHub Desktop.
Split text in max 5000-character-long parts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
long_text = 3000 * "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " | |
COMPREHEND_LIMIT = 5000 | |
lines = long_text.split(".") | |
current_text = "" | |
for line in lines: | |
if len(current_text + line) > COMPREHEND_LIMIT: | |
# EXECUTE COMPREHEND | |
print(f"Executing Comprehend on {len(current_text)} characters") | |
current_text = "" | |
current_text = current_text + line | |
if current_text != "": | |
# EXECUTE COMPREHEND | |
print(f"Executing Comprehend on {len(current_text)} characters)") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment