Multiline dropdown causing problems with ChatGPT API request

Hi all,

I’ve run in to a few unique problem that I hope someone can lend a hand with.

The problem

I have an app where a user can input/type dynamic choices in to a multiline dropdown (see below)

When the user presses the “Generate” button, an API call is triggered to ChatGPT which then sends back a small blog post based on those words input in to the multiline dropdown.

That’s all working as I want it to. However, if I copy and paste those words from an external source in to the multiline dropdown and then press generate, an issue arises where three or four words will be added on their own line before it outputs what it should. See below as an example.

As you can see, it’s added “,cultured restaurants” before outputting the correct thing.

Now I’ve done endless testing on this problem and have found that when the descriptive words are typed then the output comes back as it should. But when I copy and paste the descriptive words from somewhere else, it add’s random words to the beginning of the output.

Can anyone point out where I’m going wrong? Or is there a way that I can run a workflow (regex maybe??) that trims or removes the first line of a sentence if it has less than 10 words before saving to the DB?


@mikeloc - sorry to tag you in here but do you have any idea how I would achieve this?

Sorry, but I don’t think I can help here. I obviously have no idea why it’s adding the random output at the beginning, and unless there is something consistent about the random output, I don’t see how you could use regex (or maybe even Bubble’s :split by operator) to remove it.

Just out of curiosity, is there a reason you are using a multi-dropdown? I assume the user is typing their own texts in there, so maybe it’s the multi-dropdown that is causing the issue, and maybe you could try using a multiline input to see if the same thing happens? Again, though, I really have no idea what’s going on or how you can fix it.

1 Like

Yeah, so the reason I’m using a multi-dropdown is because I’m saving the “descriptions” to the database for that user so when they come to write their next blog post, they can quick select a previous option that they’ve already used.

Damn, I thought if anyone would know how to point me in the right direction it would be you but I fully understand just how tricky the request is. Ive been trying to test all sorts of regex today and nothing seems to be working. Looks like I’ll have to come up with another solution. Thanks for replying!

Is there anything consistent about the random output? Like, is there always a line break after it?

If there is one consistency it’s that when I copy and paste descriptions, the first line output is always less than 5 words. It’s only ever 3 or 4 usually. This was the regex I was playing around with regex101: build, test, and debug regex - which seems to do the trick but I can’t work out how to implement it.

Okay, but you are saying the number of words at the beginning is inconsistent, so I don’t know how you could rely on it. Is there always a double line break as shown in your screenshot?

No there’s not always a double break. There’s only a double break if the descriptions are copy and pasted in. If the descriptions are typed then there’s no line breaks at all. The correct output is shown.

The number of words at the start are inconsistent but they are always ever only 3-4. So I was thinking that if there’s less than five word in the first line, then don’t save them to the DB. Or maybe I’m not explaining correctly. Let me know if I’m not and I can add more images etc.

Okay, so if there is always a double line break in the copy/paste scenario and the number of words on the first line is always less than five, then even though it seems pretty hacky to me, you could try something like this with the :split by operator.

The first :split by uses a double line break as the text separator (you literally press the Enter key twice in the field), and the second :split by uses a space (you literally press the Space key).

Then, you can use the :split by operator in the workflow action to get rid of the first item in a split by a double line break. Ignore the join with at the end… I was just trying to get something to work.

Anyway, I have no idea if this suggestion will help you, but it’s something, and you can play around with the concept if you want.

1 Like

Ok great, thanks for that Mike. That will definitely put me on the right path. Really appreciate your help!

1 Like

I’ve had similar issues with this when using the GPT3 API, even when I coded it myself in node.js. So, as far as I know this is not a specific Bubble problem. I’ve “solved this” by trimming the response as well.

1 Like

@deconinck.louis - I never thought of trimming the response! Do you have an example handy on how you managed to do it?

@mikeloc @deconinck.louis - I think I’ve managed to fix it. It’s certainly not the cleanest solution but as the problem looks to be with ChatGPT’s API call then someone else might find the solution helpful.

I ended up using the :find-and-replace feature and then added this regex pattern -


Then I added a single space to replace it.

Screenshot 2023-01-26 at 1.55.01 PM

Any new line that’s under 8 words gets replaced with a single space and then I :trimmed the space off.

Like I said, it’s not ideal but hopefully someone saves themselves a few hours if they run in to the same problem.

This topic was automatically closed after 70 days. New replies are no longer allowed.