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.
Quick Response to a Bubble Coaching Client's Question
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 a text back from the text generator OpenAI, their API, sometimes it contains unwanted line spaces. How do you remove that and get much nicer formatting of your text in Bubble?
Setting Up the 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 re-initialize 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 backslash ends and that is a way of sending a line space in JSON and how then do I remove that?
The Problem with Find and Replace
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.
The Solution: Using Trimmed in Workflow
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 a 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.
Setting Up the Workflow
So I've got my API call here to OpenAI and then I'm just going to assume as is most commonly used 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.
The Key Step: Using Trimmed
I said this would be brief, 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 yep very simple, this is what we're leading up to, we add in trimmed and trimmed removes any spaces like with the spacebar or any line spaces at the start and end of the text.
Conclusion
So hopefully that will help you remove any unwanted line spaces in your OpenAI generated text.
Get the Complete Bundle for Just $99
Access 3 courses, 390+ tutorials, and a vibrant community to support every step of your app-building journey.
Start building with total confidence
No more delays. With 30+ hours of expert content, you’ll have the insights needed to build effectively.
Find every solution in one place
No more searching across platforms for tutorials. Our bundle has everything you need, with 390+ videos covering every feature and technique.
Dive deep into every detail
Get beyond the basics with comprehensive, in-depth courses & no code tutorials that empower you to create a feature-rich, professional app.
Save over 70%!
Valued at $80
Valued at $85
Valued at $30
Valued at $110
Valued at $45
Can't find what you're looking for?
Search our 300+ Bubble tutorial videos. Start learning no code today!
Have questions?
We have answers!
Find answers to common questions about our membership plans, programs, and more.
We're here to help you launch your no code SaaS. Reach out to the team and we'll double check our vast library for useful content. We'll advise you on how we'd tackle the same problem and there's a good chance we'll record the video to help the wider community.
As a Planet No Code member, you'll receive a discount on our Bubble coaching sessions. Monthly members receive a 10% discount, while Annual members receive a 17.5% discount. To redeem your discount, simply log into your account and book a coaching session through our platform.
Our 8-week intensive mentorship program is designed to provide personalized guidance and support to help you accelerate your startup journey. You'll be matched with a startup expert who will work with you one-on-one to set goals, overcome challenges, and make rapid progress.
To apply for the Mastery Program, simply click the "Request Invitation" button on our pricing page and fill out the application form. Our team will review your application and schedule a call with you to discuss your goals and determine if the program is a good fit for your needs.
We accept all major credit cards, including Visa, Mastercard, American Express, and Discover.
While we don't offer a free trial, we do provide a 14-day money-back guarantee. If you're not completely satisfied with your membership within the first 14 days, simply contact our support team, and we'll issue a full refund.