Limited Time Offer: Watch All Our Bubble Tutorial Videos for Only $99 per Year!

Bubble & OpenAI - How to remove unwanted line spaces

In this Bubble tutorial video we demonstrate how to remove unwanted line spaces from text generated by OpenAI in your Bubble app.

This video is going to be really quick and it's a response to a question I've received from a Bubble coaching client I've been working with over the last few weeks. And that is around when you receive text back from the text generator, OpenAI, their API, sometimes it contains unwanted line spaces. How do you move that and get much nicer formatting of your text in Bubble?

Overview of OpenAI API call

So I've got an API call set up to the OpenAI API. And you have to check out another tutorial of how to do that. But if I initialize or reinitialize the call and just wait for OpenAI to get back the data I've asked for, here is my AI generated text. And you can see that there's a number of these \n, and that is a way of sending a line space in JSON. And how then do I remove that? Well, I've seen some people trying to use find and replace. And I think that doesn't work with Bubble because Bubble is almost too clever for that. When Bubble receives this data back, it knows that it's JSON, it knows that that's a line space, and so it converts it into a line space for you.

So this is how I would approach getting rid of that unwanted line spaces before and after, sometimes after in this area here, your API call. So if I click Save, and then I go onto the page here, which I've got just a text box and an area to display my text. I'm going to delete that.

I'm just going to show you very simply what you do in your workflow to format it like this. So I've got my API call here to OpenAI, and then I'm just going to assume, as is most commonly the use, that you're going to save the response. So I'll just call this AI text as a new data type, and then call this text. Now, I said this would be brief.

Using trimmed

This is what the whole video has been leading up to. We go to results from the OpenAI call. We then go to choices because that's the different versions that OpenAI has returned. We go to the first item, we go to text, and then we go yeah, very simple. This is what it's all been leading up to. We add in trimmed. And trimmed removes any spaces like with the space bar or any line spaces at the start and end of the text.

So hopefully that will help you remove any unwanted line spaces in your OpenAI generated text.

Latest videos

lockcrossmenu