ChatGPT and Ignition Perspective

With the recent wide release of ChatGPT, many Corso Systems team members have been learning the platform and testing it’s capabilities. We have seen folks online making websites with ChatGPT doing most of the coding work, we have seen people write essays and poetry with it, and we have even tested the waters by trying to use it to generate a blog post. (We did not use the results. Although it was a fun experiment, the post wasn’t up to our usual standards.)

In an evening Slack exchange this week, Adrienne Harvey off-handedly suggested that ChatGPT could be fun to try on a task we do every day: building Ignition Perspective Views!

If you have been following Corso Systems for any length of time, you know how we like to be on the cutting edge. For example, when the Ignition Perspective Module was still in beta, we did the first Perspective Project in Production. Then, when the Ignition Exchange was announced at ICC 2019, we had the first third party Ignition Exchange Resource. With a track record of quickly implementing our ideas once we realize they are possible, we are here now to stake our claim as the first company to use ChatGPT to build Ignition Perspective Views.

ChatGPT Basics

ChatGPT is a Large Language Model (LLM) platform from the company OpenAI. An easy way to understand how to use it is to imagine visiting the Google search page in the late 90s when all you had was a text field. After typing a search term into the text field and hitting enter, Google would return pages of search results. ChatGPT is conceptually similar. But now, instead of search results, ChatGPT will return answers to your questions, information on what you are asking about, have a conversation with you, or even generate content for you.

Think of ChatGPT as Google, but instead of having to spend time poring through the results, ChatGPT does the work for you faster than you could—then returns the answers directly. As an added bonus, if you need more detail you can simply ask for it.

Example use cases we have tried or observed in the wild:

  • Summarize a website into the top eight criteria related to a topic (in our case, we compared the Corso Systems Career page with some of our competitors)

    • Using the newly summarized criteria, ChatGPT rated the web pages we gave it (which included some of our competitors’ careers pages, and yes they scored decently which was awesome) on a scale from 1-10

    • Using those same criteria we asked ChatGPT to provide five suggestions to improve another web page (in this case, the Corso Systems Careers page). The main note for improvement that ChatGPT provided was to include more information about our culture.

  • Create a Tweet, LinkedIn post, and Facebook post based on a Corso Systems blog post (We haven’t used any of these verbatim, but they’ve provided inspiration in some cases)

  • The Automation Ladies Podcast has used ChatGPT to extract interesting quotes from a transcript of an episode

  • Generate a signature cocktail recipe, and a signature mocktail recipe (non-alcoholic) for the A3 Automate Show in Detroit in May 2023

  • Provide the optimal strategy for a given set of cards in the card game Dominion (we like to play Dominion, so why not have some fun with ChatGPT too?)

  • The topic of this post, using ChatGPT to build a Perspective View

Important Caveats with ChatGPT

We have found a few caveats. First (much like Google) you need to learn how to use the tool. The way you ask questions can significantly impact the results you get. And sometimes you need to feed in information for ChatGPT to know what to do and how to respond. If your request is related to a topic like general web development knowledge which already has a large amount of information available online, ChatGPT can pretty easily write code for you. But if you are working with a something specialized like Ignition—without millions of posts on Stack Overflow—you will need to provide extra information before ChatGPT can give you useful results.

Second, there is a limit to how much output you can get from a response. When writing code, it will sometimes stop at an arbitrary point. If this happens, just type the word Continue and it will keep going. As you will see in our examples below, this may cause formatting issues in the responses, especially with JSON data. This leads to our final caveat…

While ChatGPT can do a lot of the work, sometimes it is still more efficient to use it as a starting point and finish the rest of the work yourself. You will also probably experience this if you enter a prompt during one session, then go back later to recreate the work and get a different result from the same input. You still need to use your experience and critical thinking skills to vet the results before you blindly put them into use.

Can ChatGPT Build Ignition Perspective Views?

We first had to determine if ChatGPT could generate a Perspective View at all. So, the first step was to see if ChatGPT was up to the task of creating a JSON file in the first place.

Screenshot of ChatGPT's answer for a prompt asking if it can generate JSON. The answer is yes, since it is a language model it can generate text in various formats, including JSON

Adrienne first set up a simple flex container view with just a label and a text field, then changed the background color on the root container to an arbitrary golden yellow (to make sure the JSON included an example style). She then exported the JSON for the view by holding shift and right clicking on the view in the Project Tree in the Ignition Designer, and then selecting “Copy JSON”.

She asked ChatGPT to create a new version of the JSON object with a red background, and pasted the copied JSON for this View into the prompt. ChatGPT generated the new JSON. She copied the JSON code from ChatGPT, then went back to the Designer, holding shift and right clicking on the View again, she selected “Paste JSON” and the view updated with the new background color.

Example screenshot with the prompt described in the paragraph above including the pasted in JSON example from Ignition
Example screenshot with the ChatGPT generated JSON with the red background - ready to be pasted into Ignition
Step one of pasting the generated JSON into the Designer: select the view in the project tree

Step 1: select the view in the project tree

While holding shift, right click the view to access a menu for pasting JSON into the view

Step 2: Paste the generated JSON into the view

If the view loads with the change - SUCCESS!

Step 3: Verify that the view loads and the change appears.

This example highlights a few important points for using ChatGPT in more niche applications than traditional web development.

  1. You need to provide ChatGPT with context about the task

    • “This is a Perspective View” tells ChatGPT what you are working with, and specifies how to return results to you.

  2. ChatGPT is great about generating code, but isn’t well versed in generating file structures

    • Ideally, you could take a project export zip file and recreate that from ChatGPT. This would be easier to import, but would take a lot more effort to figure out how to implement this.

  3. ChatGPT will not create everything from scratch

    • This example was great because it had a known quantity to change, the background color. If you asked ChatGPT to add a checkbox to this view with no concept of what a checkbox is or how it is represented in Ignition, you would not get the right results.

Creating a More Advanced Ignition Perspective View With ChatGPT

The next step was to try a more advanced Perspective View with ChatGPT. Given how much time you can spend building a form with all the various fields and field types, we felt like this could be a solid opportunity for ChatGPT to prove itself.

By taking a very iterative approach, we started with a simple view: a flex container view with an additional flex container wrapped around a label and a text field. We added a parameter to the view called firstName, set up a bidirectional property binding on the text property of the text field to this parameter, and then added a button to write a record to the database with the value of the firstName parameter. When the button was clicked, we reset the value of the parameter to an empty string.

Screenshot of a simple example view created in the designer to give ChatGPT
the ChatGPT prompt with the pasted JSON from the Designer

We then told ChatGPT this was a Perspective View and it analyzed everything for us:

ChatGPT analyzed the view and determined it is a JSON object  that defines a user interface component called a "Perspective View" and what it contains.

Next, we told ChatGPT to generate a Perspective View with a first name and a last name field along with a button to save to the database and clear the form. Without hesitation (although this was at lunchtime so the response came in at a glacial pace) ChatGPT churned through the JSON code and returned a view with a First Name and Last Name field. It properly set the label text, created the parameters on the view, and mapped everything correctly in the database on the button press, even clearing the form when you clicked the button. Yes, that’s right—it even wrote the records to the database!

a ChatGPT prompt for generating the JSON code for a Perspective View, with the resulting JSON code generated

ChatGPT’s code

ChatGPT generated an explanation of the JSON code it returned

ChatGPT’s explanation of what it generated

The ChatGPT view in the designer

The View in the Designer

The data saved in the database from the view

Saving the Results

The Next Iteration: Making the View More Functional

As we mentioned before, learning how to use ChatGPT most efficiently is part of the experience, so let’s go on a journey!

Seeing how the previous iteration worked, we created a new view in the Designer with a dropdown field and some generic options. We passed this view into ChatGPT and asked it to build a new view with two text fields for first name and last name, as well as a dropdown for selecting an Ignition Certification level—IU Credentialed, Core Certified, and Gold Certified.

New prompt for ChatGPT including JSON for a perspective view with a dropdown

At first glance, it returned what looked like a view, although importing it into the Designer didn’t work. The code snippet from ChatGPT had cut off early. Assuming it had hit the character limit, we asked ChatGPT to break up the responses into smaller chunks. Ans while that worked to give us the entirety of the View, there was something completely wrong with the button scripting and thus the view would not import. When trying it a few more times, it simply wrote out the code from the beginning each time.

using the continue prompt to get a complete answer

ChatGPT typing out the same response multiple times

ChatGPT having issues writing the button script after adding the drop down.

ChatGPT’s attempt at the button script after adding in the dropdown. Notice it doesn’t use a system.db.runPrepUpdate() call like the original button did.

Original button script with correct function call

The original button script using a system.db.runPrepUpdate() function call.

After taking a break (one of the best ways to solve hard problems) and watching some examples of generating website code from ChatGPT, we learned about the “Continue” prompt which tells ChatGPT to continue typing its response.

The Continue prompt saves the day

We also thought more about the process and decided that the way it broke when adding in the Dropdown meant we might be throwing too much complexity at ChatGPT. Our next attempt simplified this a bit.

So, we went through the same process of “here is a Perspective View with a first name” to prime ChatGPT with a Perspective View. We then put in only the flex container with the dropdown, by copying the JSON directly from the tree and telling ChatGPT that this was a dropdown that can go in a Perspective View. It analyzed the JSON and came up with a decent answer.

The results of priming ChatGPT with JSON from a Perspective View

This time when asked it to generate a view with a First Name and Last Name Field, and a dropdown with the certification types listed earlier, it produce the JSON for a view that worked! We did have to do the “continue trick” once, and since it was JSON starting in the middle, the code formatting broke, but we were able to easily add two curly braces at the end once we copy/pasted both code snippets. We copied both snippets into a text file to combine them, added the curly braces at the end and then pasted it into the View. This is just one of many examples of where using your experience and critical thinking are required to get the results over the finish line with ChatGPT.

ChatGPT prompt for generating a Perspective View with text inputs, dropdown, and save button

ChatGPT Prompt to generate a view with two text fields and a dropdown

The completed view in the designer, including the dropdown

The completed Perspective View with a dropdown!

We followed a similar process for adding a checkbox to the form and came up with the same results to prove ChatGPT can absolutely generate Perspective Views with the right prompts!

The completed view in the designer, including the dropdown and a checkbox!

On this second attempt, since we hadn’t thought through database side, we figured this was a good opportunity to try ChatGPT as a support tool. So, we asked it how to add column to a MySQL Database. This type of question would normally be more suitable as a Google search to check syntax, and would require going to at least one page—likely Stack Overflow—to find the answer. Instead, ChatGPT did that all for us and explained everything as well.

Using ChatGPT as a support tool - information on how to add a column to a table in MySQL including explanation and sql code

What is the Best Way to Automate Creating Perspective Views?

Overall we had to build three examples of what we wanted to see in a form. Text field, dropdown, and a checkbox. If we wanted to add more types of fields, we would need to build one example of each to import into ChatGPT. Yes, we could probably generalize things a lot more, and teach ChatGPT to do Perspective components for us, although we don’t necessarily think that is the right approach for a variety of reasons:

  • First most of the work we do is under NDA and there is zero guidance on how intellectual property concerns are addressed when using ChatGPT. So, using it for client projects would not make sense right now. This might be addressed later, but isn’t a risk worth taking right now.

  • Second, in the amount of time it takes to figure out how to use ChatGPT to build exactly what you want, we could have done everything manually in Perspective, deployed the code to production, tested it, and taken the client out to dinner. Yes, this could be alleviated with more experience. However, we think the true power of ChatGPT is not in doing the work for you, it is using ChatGPT as a support tool to help accelerate your brain cycles and multiply your avenues for getting the right answer quickly.

  • Third, ChatGPT only gets you in the ballpark. We would still need to build the database tables, integrate the form into the rest of the application, test and validate everything, and make sure it worked for the client—regardless of who wrote the code.

At Corso Systems, we normally perform these tasks using some of the internal tools we have developed for using object relational mapping Python scripting libraries in Ignition. This lets us connect to a database or specify a particular data model we want to use, then it parses through the columns or the model to generate the data we want the user to interact with, and lastly it builds the JSON for the forms from there. We have built a library of standard form components we can use across projects for anything from text fields, drop-downs and checkboxes to radio buttons and sliders.

This approach builds on our expertise and experience while automating tasks where we can use style classes to format our components to look good in the project without having to spend time wiring up the same property bindings we have done on every single form. This gives us a standard way to interact with a common tool we use in our Ignition development, and overall it streamlines our developer experience.

ChatGPT Limitations

Through this process we found that a major limitation of ChatGPT is there is no easy way to share your work. The only feasible options seem to be screenshares and copy-pasting text. While this is okay for explaining what you are doing to someone else, it still requires you to send them all of the text and code from your prompts if they want to recreate your results. It is also not guaranteed that they will get the same results—even with an identical prompt, which makes ChatGPT a very difficult tool for collaboration.

Depending on the time of day, ChatGPT can also run into a lot of network timeout issues. This will likely improve over time as they build up their infrastructure, but it is still frustrating to see the results take a long time to populate during business hours, or to get a network timeout in the middle of your code generation.

Finally, while it is a cool concept, you have to sit there and literally watch ChatGPT type out the code as it is being generated. This is fine if you are using at night when the speed of the system is faster, but doing this as a lunchtime experiment was brutal. One of the first Perspective Views using the text fields and the dropdown took almost eight minutes to type out during the day, and nearly a minute at night. Comparing this to a nearly instantaneous JSON file generation when using our scripting libraries was an exercise in frustration.

These issues will likely improve over time as the platform matures, and will make ChatGPT a more powerful tool in our technology arsenal.

The other major question about ChatGPT, and one of the main reasons it will take a long time to take off for tasks like this in manufacturing, are the unresolved and unknown issues related to intellectual property and who owns what code. Since ChatGPT is likely learning from what is entered into it it would be very easy for someone to unknowingly, or even maliciously put trade secrets and code not meant for general consumption into the tool and put a lot of people and companies in very murky legal waters. Most projects include rigorous Non-Disclosure Agreements (NDA). Most companies looking to keep their information private would see using ChatGPT as a violation of an NDA. This issue seems to be popping up already in the legal world where people are trying to use AI tools as lawyers in relatively minor cases like fighting traffic tickets. We expect this issues to be ongoing and not be resolved anytime soon.

Wrapping Up

There is no denying that ChatGPT is very powerful technology. It feels just like it did when we went from Webcrawler, Dogpile, Altavista, and all the other basic search engines that existed in the mid-90’s to using Google—except now we are going from Google to the next level.

As ChatGPT matures and people figure out how to use it, maybe someday we can give ChatGPT a control narrative, a P&ID drawing, and a list of what data needs to be collected, and it can generate an entire Ignition project—although that scenario seems to still be a few years off from reality.

Until then, we will keep exploring the possibilities of ChatGPT and how we can leverage it to make our engineers’ lives easier, build better tools for our clients, and come up with ever more exciting content like this to share with the world!

Previous
Previous

Combining the Power of ISA-95 and Sparkplug B

Next
Next

P&ID Drawings 201: Reading Real World Examples