Split text into chunks of X words/characters (free API)

For one of my apps I need to split long texts (sometimes 10,000 words+) into chunks of n words. I made a simple API for a template I made (TEMPLATE: CustomGPT - train your own GPT chatbot) that you can host yourself, so I’m just putting it here as a ‘take it or leave it’ kind of thing. No support guaranteed, but it’s free :slight_smile: Also, no guarantees this is the most efficient API or even the ‘best’ way to do it in Bubble, but I use this for a bunch of apps and have never gone past the free tier of Google Cloud Platform.

Files here: Dropbox - Memory Splitter - Simplify your life

Rough instructions
Deploy to Google Cloud Platform App Engine. You can Google how to do it or ask ChatGPT for help…

Make API call from Bubble (in backend workflow or page workflow are both fine). The URL will be https://your-application-version-name.appspot.com/split-text. Set headers to content-type = application/json.

{"text": <text>, "wordLimit": <wordLimit>, "characterLimit": <characterLimit>}

Provide the text you want to split formatted as JSON-safe. Provide the length of the chunks in words and characters. The API will split at whichever limit comes first.

Example input
{
“text”: “This is a sample sentence. It will be split into chunks according to the word and character limit.”,
“wordLimit”: 5,
“characterLimit”: 20
}

Example output

{
“chunks”: [
“This is a sample”,
“sentence. It will be”,
“split into chunks”,
“according to the”,
“word and character”,
“limit.”
]
}