FT Optix and ChatGPT Integration

Home / FactoryTalk Optix / Advanced Topics and Use Cases

Description
Getting to know how to integrate a ChatGPT bot in your HMI or SCADA with FactoryTalk Optix and OpenAI API. You have to have an OpenAI account and use .NET and C# to perform a REST API transaction from Netlogic. With this method a new employee that does not speak the preset HMI language would be able to interact with the Panel or SCADA, or even make calculations needed before entering the setpoints. Just up to your imagination.

Download the sample code here:
https://github.com/xavierflorensa/FactoryTalk_OpenAI_Multilanguage

Contributed by Xavier Florensa – YouTubeLinkedInGitHub


Transcript
(00:01) Hi everyone. In this video, I will show you how to integrate chart GPT with factory talk optics. First of all, let’s see the demo to uh understand what I’m trying to do. Imagine you want to translate a sentence from English to German. You can enter German here and then translate. So this is the prompt we will give to JPD like translate the following English text to German.
(00:42) Hello, how are you? Here we have hello dear. You can also choose other languages. style for instance French whatever you want what you call so let’s see how to do this and why to do this uh we are always used to this jpd environment You make a question and you get the the answer. Well, we have not enter now but imagine uh in the HMI it’s a human machine interface you would use different languages that
(01:47) the ones that was initially designed in the machine. So imagine a new operator comes and he doesn’t speak English or whatever language you have set up in the machine. With this method, the operator will be enabled to understand what’s on the HMI or uh you may think this is useless. On the other hand, this is fun and this is just to demonstrate that I can that you can but it’s up to your imagination to find an application that uh this tool can be applied.
(02:37) So let’s take a look at the application. But before let me go to you need to have a openi account in platform openai com you create a new account and then you need an API key. So we will use the open AAI API. Once you have this, you can see the tokens yours drawn. But let’s focus on the application. Here we have this main page with all the language, the prompt, the result.
(03:33) For instance, each time you get a result, you get this uh JSON file as a response and in the optics file. Apart from calling the API, I also make a parsing to get only the response the translated language. Here we also have some variables to interact between the optics and C in the logic with the prompt response string the churn language and finally let’s take a look at the the logic here you will see that on the start and stop methods we use nothing but we just create an export method
(04:38) called translate. This is the method that will be executed as soon as you click on the button. When you click here, you will execute this method to translate whatever is on the prompt. Then let’s take a look further here. You have to introduce the API token here. Take a look at this variable. This is an environment variable from my computer.
(05:26) Since I don’t want to share my secret K here. To do this, you can go to your uh Windows to the environmental variables and set this variable to your secret API. then your a API key is protected. Then you also have to use uh this endpoint for the rest API from OpenAI and then you have to perform an HTTP request with a prompt.
(06:08) To build the prompt, you can use this variable. And this is the prompt. Translate the following English to the chosen language. Hello world. So, so you have once you have the result, you want to parse the JSON response and extract only the translated message. Okay, you’ll have this code in GitHub. Uh once you save this you’re ready to execute your captivity aquarium and let’s try with different languages.
(06:57) finish. We can also try in Thailand. You can also try Russian. You can also try Greek. You can also try and sec. So whatever you want then um this is all. I hope you enjoy. Thank you very much.