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