Not-exactly-live Bubbling with @keith: Transcript - @keith teaches GPT-4 to write Bubble element plugins

Hey @keith. I want to say thank you for this post cause it’s a great jumping-off point for starting my journey in building my own plugins with ChatGPT. Feeding it stuff from the manual, code from other plugins and the convos you’ve had with CGPT is really helping me out!

I can’t believe i actually can understand how to start plugin building in a few hours!

2 Likes

Hi @keith , really great stuff here, it opens up a lot of possibilities! Any news of sharing the intro prompt? :upside_down_face:

1 Like

Like a lot of folks here, I’ve been a little derailed lately by the pricing thing and that’s kind of taken all the joy out of interesting experiments like this one, or working on new features in Floppy or whatnot. Any Bubbling time I’ve had has been spent doing math figuring out the costs of doing anything in Bubble and just shaking my damn head, as they say.

That being said, I’ve been using GPT-4 as a writing partner for other projects and it’s just super great for that. Very similar use case to co-writing code and it’s excellent at taking one’s own writing (or anything for that matter) and synthesizing it into something new. (For example, turning technical documentation about some topic and turning into a general introduction to some topic in lay terms).

Depending on what happens with Bubble pricing I may get re-enthused about Bubble, but I’m very standoffish right now. (Which is unfortunate as I was kind of hitting a stride in terms of innovating on Bubble and building more complex features that build on a lot of previous work.)

5 Likes

@keith could i share your on another channel? telegram?

Hey @keith!

I’ve been spending the last few days trying to “train” ChatGPT to help me build plugins. Been feeding it the Bubble plugin manual (such a sad little thing that is), posts from the forum and one or 2 YT transcripts on the subject. I just want to do a “peer review” with you about what I think it understands so far:

Start of ChatGPT explaining to me the differences about building a Bubble plugin

When developing a Bubble plugin, there are specific functions, practices, and structures you need to follow to ensure compatibility with the Bubble platform. Here’s a more detailed breakdown:

  1. Plugin Types:
  • Bubble plugins can be one of two types: Element plugins or Action plugins.
  • Element plugins create new visual elements or components.
  • Action plugins define new actions or integrate third-party services.
  1. Initializing a Plugin:
  • To initialize your plugin, you need to define an instance.data object in the initialize method. This object stores any data or state related to the plugin instance.
  1. Element Plugins:
  • Element plugins require the definition of a render method. This method is called when the element is rendered on the page.
  • Inside the render method, you can access the element’s properties via the properties object and set up any event listeners.
  • To update an element’s value or trigger a custom event, use the instance.publishState and instance.triggerEvent methods, respectively.
  1. Action Plugins:
  • Action plugins require the definition of a function for each action you want to create.
  • The function must be named in the format actionName_run. For example, if your action is called “Send Email,” the function should be named sendEmail_run.
  • Inside the action function, you can access the action’s properties via the properties object and call any necessary APIs or services.
  • To return data or indicate that the action has completed, use the instance.publishState and instance.sendResult methods, respectively.
  1. Exposing Properties:
  • Both Element and Action plugins expose properties that users can configure within the Bubble editor.
  • To expose properties, you need to define them in the Plugin Builder’s “Property Editor” section.
  • The properties can be of various types, including text, number, boolean, color, date, etc.
  • Users will configure these properties in the Bubble editor, and you’ll access their values using the properties object within your plugin code.
  1. Accessing Bubble APIs:
  • When building a plugin, you might need to interact with Bubble’s APIs, such as fetching data from the Bubble database or triggering a Bubble workflow.
  • To access these APIs, you’ll need to use the instance.context object and the associated methods, such as instance.context.request, instance.context.uploadContent, and others.

By following these specific structures and practices, you’ll ensure that your Bubble plugin is compatible with the platform and works seamlessly within Bubble apps.

Me: Is there anything about asynchronous actions that we should be careful of?

Yes, when working with asynchronous actions in Bubble plugins, it’s crucial to handle them properly to ensure smooth execution and prevent unexpected behavior. Here are some points to consider:

  1. Handling Promises:
  • Asynchronous actions typically return Promises. Make sure you handle these Promises using async/await or then/catch to manage the flow of your code.
  • When using async/await, declare your function as async. For example, for an action named “Fetch Data,” the function should be defined as async function fetchData_run(...) {...}.
  1. Error Handling:
  • Implement proper error handling using try/catch blocks when working with async/await or catch method for Promises. This helps prevent unhandled exceptions and provides meaningful error messages to users.
  1. Returning Results:
  • When your asynchronous action is complete, use the instance.sendResult method to return the results to Bubble. This method accepts an object with key-value pairs representing the data you want to return.
  • If you’re using async/await, call instance.sendResult within a try block after your asynchronous action is complete. For Promises, call it within the then method.
  1. Reporting Progress:
  • For long-running asynchronous actions, you can report progress to users by using the instance.publishProgress method. This allows you to display progress updates within the Bubble editor, keeping users informed.
  1. Timeouts:
  • Be aware of potential timeouts. If your asynchronous action takes too long, it may exceed the timeout limit set by Bubble or the browser, leading to unexpected termination. Make sure your action handles such scenarios gracefully.
  1. Event Loop:
  • Since JavaScript is single-threaded, long-running asynchronous actions can block the event loop and make the user interface unresponsive. Make sure to use appropriate techniques, like breaking down tasks into smaller chunks or using Web Workers, to avoid blocking the event loop.

By considering these points, you can create more robust and reliable asynchronous actions in your Bubble plugins, ensuring smooth integration with Bubble apps and a better user experience.

Me: How about callbacks and the context.async function?

In Bubble plugins, you can also use callbacks and the context.async function to manage asynchronous actions. Here’s how to do it:

  1. Callbacks:
  • You can use callbacks to handle asynchronous actions by passing a function as an argument to another function. This callback function will be invoked when the asynchronous operation is complete.
  • When using callbacks in Bubble plugins, make sure you handle errors and pass them as the first argument to the callback function, following the Node.js convention.
  1. context.async:
  • The context.async function is a utility provided by Bubble to help manage asynchronous code. It takes a single argument, which is a callback function.
  • The callback function you pass to context.async should expect two arguments: an error and the result. The error argument should be null if the operation is successful, otherwise, pass an error object.
  • When you’re ready to return the result of your asynchronous action, call the callback function with the appropriate arguments (error and result).
  • Note that the context.async function is not part of JavaScript itself, but a utility provided by Bubble specifically for plugin development.

Here’s an example using callbacks and context.async in a Bubble plugin action:

javascriptCopy code

function myAsyncAction(instance, properties, context) {
  // Define your asynchronous function, taking a callback as its argument
  function fetchData(callback) {
    someAsyncOperation()
      .then((result) => {
        callback(null, result); // Pass null as the error and result as the second argument
      })
      .catch((error) => {
        callback(error); // Pass the error object as the first argument
      });
  }

  // Use context.async to manage the callback
  context.async(fetchData, function (error, result) {
    if (error) {
      instance.publishState("error", error.message); // Handle the error
      instance.triggerEvent("error_occurred");
    } else {
      instance.publishState("result", result); // Publish the result
      instance.triggerEvent("success");
    }
  });
}

Using callbacks and context.async provides an alternative way to manage asynchronous actions in Bubble plugins. However, with the introduction of Promises and async/await, these newer patterns are generally recommended for handling asynchronous code in JavaScript, as they can make the code more readable and easier to reason about.

END

The reason I’m doing this is to try and work out a “Bubble Plugin Builder’s ChatGPT Prompt Starter Pack”. It’ll be awesome sauce if you could review this for me :pray:t4:

2 Likes

Hey @ihsanzainal84, my own work on this already compresses those concepts much more and as the Microsoft “sparks of AGI” paper finds, GPT-4 is rather biased AGAINST novel tool use, even if you provide the tools. You can see this in my videos where it fails to include my helper functions, but then will, if asked something like, “are you SURE you’re reading that List in the right way?”, reconsider with an “of course I effes that up!”

Note that none of this works in standard GPTChat, only GPT-4/ChatGPT Plus. (And not in the standard 8K context window of the GPT-4 API… the prompt size is pushing the boundaries of the 32K content window.)

I’m still not sure what to do with my previous work. It’s clearly not monetizable here, and I don’t see any benefit to open sourcing it at the moment. It’s complicated.)

2 Likes

I’ve been using GPT-4 since release and while it it’s leaps and bounds more useful, you are right. I’ve actually given up trying to have ‘threads’ in ChatGPT.

What I’m doing now is very precise prompting when in ‘novel’ use cases and simultaneously using other AI systems. On the flipside I think I’ve leveled up my JavaScript game since I can’t give it precise prompts if I don’t understand the topic myself.

Saw your announcement in the other thread. You really moving to greener pastures?

1 Like

Have you seen this prompt? It seems to work better than my last suggestion to compress the context into far fewer tokens.

Compressor: compress the following text in a way that fits in a tweet (ideally) and such that you (GPT-4) can reconstruct the intention of the human who wrote text as close as possible to the original intention. This is for yourself. It does not need to be human readable or understandable. Abuse of language mixing, abbreviations, symbols (unicode and emoji), or any other encodings or internal representations is all permissible, as long as it, if pasted in a new inference cycle, will yield near-identical results as the original text:

Hey @ihsanzainal84

Great stuff!

Have you been able to handle OAI timeouts reliably through try/catch blocks with async/awaits? … Or any other technique perhaps?

Copying @launchable @keith @georgecollier @mikeloc @adamhholmes @Jici for comments/feedback :smiley:

I haven’t had a need to integrate any AI features to my apps though. I use that prompt in the post as a custom instruction though someone already made a GPT for Bubble plugin building.