Easily use ChatGPT in your Custom Automations! | Node-Red Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay guys I've done it I created a plugin for node red that allows you guys to talk to GPT with reasonable ease you don't need to write any custom code debug functions none of that foolishness nope nope nope up until this point I've been testing it out and trying to make it easier to use and some of you have started to notice them in my recent videos so in this video I'm going to go over how to use the AI intent plugins and what to expect from it so first things first this video assumes that you one know about node red have node red integrated into home assistant and three have some basic Proficiency in how to use node red now if you're missing at least one of these above prerequisites uh there are links in the description to get you better acquainted with node red as well as how to install it for home assistant okay so let's talk setup AI intent is a middleman between open Ai and your system it provides an easy interface for you to use and does all the heavy lifting behind the scenes to construct the payload required by open AI as a result you're going to need to get an API token for this to work from openai so go to the platform. open.com create an account click on API Keys create a new secret key and copy this value you're going to need it now the next part of this is going to vary depending on how you have node red installed into your system but what you're going to need to find is the settings. JS file now if you have node red installed via home assistant integration you can find this file using Studio code server plug-in look for node red and you should see the settings. JS file in that folder so if you have node red installed via a Docker container just look for where your Docker is mounting your files and then within there you can find the settings. JS file under the data folder okay so inside the settings. JS file you're going to look for the function Global context and inside that object you're going to put in the following key value pair this is where you're going to want to paste your token okay so save the file and now go inside node red the actual application click on the hamburger menu manage pallets click on the install tab in the search bar type in Tech Enthusiast it should be the only plugin there and install it once installed restart node red hey really quick um I just want to call out a brand new method for adding in the open AI token which is basically the ability to add the token through the chat node configuration now the major benefit of this is that it's considerably easier to add this token and get started the downside to this is that if you want to share your automations your API token will be included in the Json so just watch out for that I do want to give a special thanks to my channel members for this particular update they were able to help me flush out several of the bugs and they were also the inspiration for this new token configuration update way let's start making automations with GPT so what I'm going to do is walk through three examples with you and by the end you should not only get a feel for how the AI intent notes work but you should also have a makeshift Scrappy mini chap spot that can control parts of your home this is assuming that you are using home assistant first let's make an automation that answers General Knowledge Questions the user node here corresponds to the section here within open AI now you can place any question you like within this text box in order for GPT to respond you're going to need the open AI chat node this node will put data in from from the user node and combine it with the settings you provide within this particular node and send it to open aai to learn more about what these properties are and how they work you can look at the documentation on open ai's website now when we run this automation the response will look like this so I provide the open AI response node to help make the object here a little bit more neater so your results will look like this instead now in this particular example we hardcoded the question in the usern node but often times our automations will require a dynamic input you can achieve this by using single curly braces for the sake of example I'm going to place the same question in the inject node and then replace the contents within the user node with the same property name inside curly braces now we're going to create a brand new automation that can answer unique questions about your environment let's grab the inject node again and as well as a template node in the template node we're going to keep things extremely simple by hardcoding some kind of fake information about our system like lights and switches now this template node does allow you to tap into home assistant to grab actual information from your system but I want to keep this example pretty basic next let's connect it to the system node now the system node is responsible for this section of open ai's completion API so at this Noe we're going to give a little context and just like we did in the user node we can dynamically pull information in from the message object using single curly braces now our system node has a bit of context as well as the fake information we provided from the template node now I'm going to add a user node and dynamically pass a question from the inject node the same as we did with our previous example and like before we also need the Open aai chat node to combine and send the data to open aai and then lastly we will use the response node to get a cleaner response object to work with just a call out here in the open aai chat choose the model that you have access to I have access to GPT 4 but not all of you may have this access so use the latest model that you have access to your mileage will vary based off of the model that you're able to use the last node that I want to touch on is called the tools node this will help you get consistent predictable responses from open AI this is important if you want to run commands based off of responses that GPT give if you can get predictable responses or responses in a predictable format it makes it a lot easier to code for these type of things let's say we want an automation that can turn off and on lights within our home assistant environment we can combine all the previous automations together with the tools node to accomplish this if you want to understand how the Json object should be constructed within the tools node check open ai's documentation as they would give you much better examples than I can but for the sake of example let's go over quickly the version that I have here so this Json is pretty straightforward we have the name this is just the name of the function we're calling it light it can be anything that you want it to be this is the description of it I believe open AI also reads the name and description in order to know what functions to run and then these are the parameters or the things that we want open AI to give us back in our case we want an action and it can be one of two things turn on or turn off then we have the entities portion so if we gave it 10 entities and it realizes that okay I said turn on the bathroom light only one of those entities fit it's going to pass us back an array of one entity ID and then the lastly is just a response it's going to say something along the lines of if I turned on this light or I turned off the bathroom light something to that effect I find that having required and listing it out ensures that they come back with something okay so I'm going to update the template to reference a real light I'm going to update the question to turn off that light I'm using this function to simplify and reformat the payload the call service dynamically reference these attributes now when I give a command without the tools node here's how GPT responds now with the tools node here's how GPT responds because the response is now consistent and predictable you can feed the answer to other nodes like for instance the call service node to trigger the intended action okay so sorry for this cutaway I wasn't planning on showing these next two nodes but after some reconsideration I think it may blow your mind and more importantly start a wave of new ideas now this brings me to the last two nodes the register intent node and the call intent node these two nodes act very similar to the Linkin linkout nodes for those of you not familiar with node red or the Linkin linkout nodes uh they allow you to connect flows or automations that are completely separate wait hold on they're actually more like uh macros in home assistant right the same concept uh the same way that you can have let's say one script that can call another script the Linkin linkout nodes do the same thing and the register intent and call intent nodes does the exact same with some additions the register intent node takes a name and description so the name property will show in the call intent node so when it is triggered it will jump straight to the associated register intent node so in its basic form the register and call intent node basically act like triggers to any automation that you can create but there's something special about these two nodes they can be used to accent open ai's capabilities behind the scenes whenever you create a register intent node it's also added as a function to GPT that it can basically call GPT uses the name as the name of the function this is why there are specific rules around the naming of these uh registered nodes and it uses the description to determine when this function can be called the call intent can then be set to this which basically allows it to call any registered intent node dynamically based on on the payload now if you're a nerd like me you probably already see the possibilities this opens up but just in case let me say this out loud and clearly these two nodes give GPT the ability to instantly trigger existing automations based on my testing the more registered nodes you create GPT can give kind of an inconsistent Behavior Uh especially if you name and describe your nodes vaguely or they start to conflict with each other so you have to be super clear if you're getting strange results or you simply don't want these nodes to affect GPT you can select this chat box which will exclude it from gpt's options now as you probably can guess I use node red for the majority of my automations and I know that the majority of you use native home assistant to create your automations recently I saw a video from future prooof homes showing a project from jackelen at least that's how I think the name is pronounced or the username is pronounced but the project is called extended open AI conversation which not only gives you the ability to use GPT in the native home assistant environment but it also lets you connect to local AI which is a local llm which means you don't need to call the cloud for any of your AI needs well I have to admit I haven't used this particular project since my primary automation creation is through node red but I have spread through some of the code and I'm a fan I liked what I saw so much that I actually adopted some of their function definitions into my personal automations using the AI intent plug-in now you can check out the link in the description to see futureproof homes video which goes into depth on how to set up and use this I I want to leave you with one last thing that I'm pretty sure will interest you so when I created K uh you can learn more about K here just watch that video I started developing these nodes to simplify y a lot of the repetitive tasks and make it easier to connect to GPT and the more that I developed the more and more ideas came to me so over the next few weeks you'll see more videos from me that highlight different useful automations that leverage these noes that I showed you in this video channel members get first access to a lot of these ideas and exclusive access to inspirational ideas that hit me in the moment and they already experienced this last week with this voicemail idea but if you want to support what I'm doing and gain access to these perks feel free to follow this arrow and click the icon to join oh and real quick after talking with a few channel members about the extended open AI conversation project one of the next things that I'm planning on exploring for AI intent is adding in support for local AI oh yeah this is going to be a fun year
Info
Channel: Technithusiast
Views: 7,658
Rating: undefined out of 5
Keywords: Tutorial, Node red, Home assistant, GPT, Automation, Smart home, Ai, Npm, OpenAI
Id: J0_mi7U0wCM
Channel Id: undefined
Length: 13min 51sec (831 seconds)
Published: Sat Jan 06 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.