Witness the power of ChatGPT controlling home automation lights through a Raspberry Pi, making life easier with plugins. Delve into the fascinating world of large language models, redefining interactions with APIs.
[0:00] Can you control your lights using ChatGPT?
[0:03] Let there be light!
[0:10] So, you definitely can. But I can hear you thinking,
[0:13] er, he’s just turned on some lights. Why am I watching this?
[0:17] But, before you click away, I want you to really think about what just happened.
[0:21] You should be intrigued by this. Something quite amazing occurred.
[0:25] Let’s break it down. We’re using ChatGPT.
[0:28] I’ve augmented it with a plugin that allows it to control hardware connected to my Raspberry Pi.
[0:34] You’ll be thinking, hmm, a plugin for ChatGPT? That must be pretty complicated.
[0:39] There’s some clever magic going on here. Well, keep watching,
[0:42] because you are in for a bit of a surprise.
[0:45] Let’s turn off all the lights and try something else.
[0:48] How about a little home automation story?
[0:52] I’ve just woken up. Well, that’s handy. The bedroom lights have come on.
[0:59] It’s time to shower.
[1:02] Brilliant. The bathroom light is on, and the bedroom light has been turned off.
[1:09] Now it’s time for breakfast.
[1:12] Well, the kitchen light has just turned on.
[1:15] And now we’ve got to go to work. All the lights have turned off.
[1:19] Well, that was a long day. We’re back from work, but we’re too lazy to cook. We’ve got takeout.
[1:26] The dining table lights up for us.
[1:28] Now it’s time to relax. We’re moving to the TV.
[1:32] The lounge is now lit up.
[1:35] And finally, time for bed.
[1:38] The bedroom light turns on, and it looks like we’ve fallen asleep.
[1:42] There’s a sound sensor in the bedroom, and it can hear us snoring.
[1:49] The bedroom light turns itself off.
[1:52] Let’s try something else. I’ve added another bit of functionality that returns the PCB way logo.
[1:57] And look at that. An auto-generated sponsorship plug for PCBWay.
[2:01] Do you want some PCBs manufactured? Looks like ChatGBT has a recommendation for you.
[2:07] It’s all very clever. There must be something very complicated in the plug-in to make all this work.
[2:12] Well, I can tell you. Plug-ins are surprisingly simple. They are just a web API.
[2:17] No different from any other API you might write or call. And my particular plug-in is really basic.
[2:23] It’s just got two endpoints. One that returns a list of lights,
[2:27] and another that toggles a light on and off. What’s impressive to me
[2:31] is that ChatGBT worked out from my simple instructions how to drive the API.
[2:36] It’s getting the list of lights, selecting the most appropriate light,
[2:39] and then it’s working out that it needs to call the toggle endpoint to switch the light on and off.
[2:44] Now I say worked out, but I’m not going to claim that it’s thinking or reasoning about the world.
[2:48] That would be a big stretch. But I am going to claim that it’s pretty incredible.
[2:53] If I’m honest, I have come across quite a few developers who would struggle to do this simple task.
[2:58] Now, obviously, this is a really straightforward demonstration,
[3:02] but the possibilities are quite mind-boggling. I could see large language models being a really
[3:06] interesting way to plug a whole bunch of different systems and services together.
[3:10] There are a ton of crappy APIs out there, and integrating them is a nightmare.
[3:15] Wouldn’t it be funny if we ended up with computers talking to each other,
[3:18] using human language instead of APIs? Now I bet you’re asking yourself,
[3:23] that old Atomic14 must be pretty clever. He writes embedded software, makes videos,
[3:28] builds hardware, and he also makes ChatGBT plugins. Is there anything he can’t do? What a guy!
[3:34] Well, how did I make this API? Obviously, I asked ChatGBT to do it for me.
[3:39] Here’s the spec I gave ChatGBT. We’re asking it to make a Flask API. I’m just using this as
[3:45] I’m most familiar with it, so I can check what ChatGBT outputs. As always, with these large
[3:50] language models, it’s definitely a case of trust, but verify. We’re running on a Raspberry Pi,
[3:56] and we want to control some lights connected to GPIO pins. Here’s our list of lights,
[4:00] along with the pin numbers. And here’s our fairly vague spec for the endpoints we want.
[4:06] We’ll let ChatGBT work out how to implement them. Let’s see what it makes of it.
[4:11] And there we go. We’ve got our nice little server.
[4:14] Here’s the code setting up the data structure for our lights.
[4:19] We set up the GPIO pins.
[4:23] And here’s the endpoint for getting the list of lights.
[4:26] And here’s the endpoint for toggling the light on and off.
[4:29] The only other thing we need is an OpenAPI spec or swagger file.
[4:33] You’ll have probably seen one of these if you’ve ever looked at API documentation.
[4:37] It’s a pain to write, and it’s quite verbose. So I’m not going to write it,
[4:40] we’ll just get ChatGBT to do it for us.
[4:43] And there we go. It’s produced everything we need.
[4:46] Life is getting very easy. I may need to find an alternative career soon.
[4:51] We can load this into an online tool to see what it looks like, and it looks very sensible.
[4:55] This is basically what ChatGBT looks at to work out how to drive our API.
[5:00] What about the hardware? How on earth did I work out how to wire up this complex circuit?
[5:05] Well, good old ChatGBT knows all about that as well.
[5:08] It can describe everything we need. A Raspberry Pi, obviously.
[5:12] Some LEDs, some resistors, breadboard, and some jumper wires.
[5:16] We’ve got some detailed instructions, and we’ve got a nice little diagram.
[5:20] At the moment, it does struggle with generating images,
[5:23] so I’ve asked it to create a mermaid diagram which we can view online.
[5:27] I mean, it’s not the best diagram in the world, but I’ve certainly seen worse.
[5:31] It’s also written as a basic blink sketch. Thanks ChatGBT.
[5:35] Obviously, I’m joking. I do know how to wire up LEDs,
[5:39] but it’s fun to test out the capabilities of the language model and see what it’s capable of.
[5:44] The only other thing we should probably cover is how you actually get the plugin wired into
[5:47] ChatGBT. Unfortunately, a lot of you won’t have access to plugins yet,
[5:52] and you almost certainly won’t have access to develop plugins.
[5:55] They are rolling out access pretty slowly, and I’ve been pretty lucky.
[5:58] But you can apply for access, and I think it’s really interesting to try out.
[6:02] For developing local plugins, you need to have a server running on localhost.
[6:06] Fortunately, we can use the excellent VS Code support for remote development.
[6:10] I’m connecting through to the Pi from my desktop machine,
[6:13] and when I launch the server, VS Code tunnels through to the Raspberry Pi
[6:17] and exposes the server on my local machine.
[6:19] To add the plugin to ChatGBT, we navigate to the plugin store,
[6:23] and then click the develop your own plugin.
[6:25] We just add localhost and the port that our server is running on.
[6:29] And that’s it. It pulls all the information it needs from the server,
[6:32] the description, the logo, and the swagger file.
[6:35] It does some magic behind the scenes, and our local plugin is available to use.
[6:39] It really is very clever.
[6:41] Now obviously, this is only a small sample of what’s possible.
[6:44] I’d be really interested in any ideas you have for something more sophisticated.
[6:48] Let me know in the comments what you would build.
[6:51] Breaking news.
[6:52] While I’ve been editing this video, it looks like plugins have been rolled out to everyone,
[6:56] and there’s now quite a few of them.
[6:58] Let’s take a look.
[6:59] There are quite a few pages to go through.
[7:01] Everyone’s been very busy creating new exciting things.
[7:04] There are some very interesting ones.
[7:06] I quite like the diagram plugin.
[7:08] We can ask ChatGBT to create us all sorts of handy things.
[7:12] For example, this is a sequence diagram showing how OAuth works.
[7:16] It’s fun to see what ChatGBT is doing under the hood.
[7:19] And here’s our nice diagram.
[7:22] There’s quite an interesting YouTube plugin.
[7:25] This gets us a summary of YouTube videos.
[7:27] Maybe you don’t need to watch any of my videos anymore.
[7:29] Just let the AI do it for you.
[7:34] There’s also the Wolfram plugin.
[7:36] This is very cool, and you can get all sorts of interesting stats from it.
[7:39] For example, global population for the past 100 years.
[7:43] It did take quite a while for ChatGBT to find the right incantation to answer my query.
[7:47] It’s nice to know that the AI is just as fallible as us.
[7:50] I also thought it might be worth showing you how the plugins work under the hood.
[7:54] We can actually just get ChatGBT to show us its thinking.
[7:58] We’ll give it the open API YAML file and ask it to explain how to turn the lights on.
[8:02] And we can use the diagram plugin to make it even clearer.
[8:06] Now that’s just amazing.
[8:08] The other very interesting thing is the new browser mode.
[8:11] This lets ChatGBT search the web and click on links and read web pages.
[8:15] It’s pretty incredible and opens up a whole new world of possibilities.
[8:19] As the two-minute papers guy would say, “What a time to be alive!”