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.
Can't find what you're looking for?
Search our 300+ Bubble tutorial videos. Start learning no code today!
Flexible Pricing Plans to Fit Your No-Code Journey
Choose the plan that aligns with your goals and start building your startup today.
Have questions?
We have answers!
Find answers to common questions about our membership plans, programs, and more.
Both plans offer full access to our learning resources, community, and support. The Annual plan provides a significant discount (over 15%) compared to paying monthly, and it allows you to lock in your rate for a full year.
Absolutely! You can easily upgrade or downgrade your membership plan at any time by logging into your account and selecting the desired plan. Any unused portion of your current plan will be prorated and applied to your new plan.
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.
If you decide that Planet No Code isn't the right fit for you, you can cancel your membership at any time by logging into your account and navigating to the subscription management page. Click the "Cancel Membership" button, and your membership will be terminated at the end of your current billing cycle.