AI that expands its features by writing its own source code

When I finished reading David Shapiro’s “Natural Language Cognitive Architecture”, I got very excited with GPT3 because I finally grasped how powerful a LLM (large language AI model) can be. David’s contributions to the OpenAI community and his youtube videos have helped fuel my interest and desire to experiment with things for myself as well.

After many months of playing with the OpenAI playground, I decided it was time to start building something more serious. I identified 3 goals that would be worth exploring and developing:

  1. an AI agent with proper memory, layers of detail, summarization, etc
  2. the capability of fetching new and updated knowledge from the outside world (using the internet)
  3. give AI the possibility of expanding its features by writing its own source code

I decided to go with number 3 because it sounded to me the most challenging, interesting, and perhaps less explored option.

My productivity system in 2022

In this past year, I’ve done significant changes to my whole “productivity system”. These changes were impulsed by two major life changes.

One, I abandoned my work life as a freelancer, switching to a full-time position. This greatly reduced my need to track many independent projects and endeavors to explore work opportunities (which I’m very grateful for).
Two, I also decided to abandon my work as a GTD trainer, in order to fully focus on developing my skills as a developer.

This doesn’t mean I have stopped doing GTD. Those who are proficient in it will recognize the core aspects of GTD in my new system, even if on a more superficial look it may not seem like so.

Getting back to writing more

A few days ago I was revisiting my old blog and found it funny that one of my last posts was about going more offline, less dependent on cloud services, and having more time for important things.

It is funny because I feel that 3 years after I’m reliving the same thing again. Well, perhaps not exactly the same, but I’m at that point of the cycle where I’m fed up with too many internet/digital distractions. I’ve been missing writing and have been making plans to restart posting on my blog on a more frequent basis, but this hasn’t happened so far… until today.

A few months ago, when I committed(to myself) to read two books a month, I uninstalled all time wasters from my phone. And, mind you, I didn’t have many. I hate mobile games and useless mobile apps. But I was still spending too much time communicating with people (Reddit, Discord, Twitter). So I removed all of that and began taking my faithful Kobo e-reader with me everywhere. Fast forward a few months and, yes, I have mostly been able to read two books every month, which has been a great experience that gives me a lot of satisfaction.

Now I’m moving to the next step, besides reading I also want to get back to writing more. For weeks I’ve been drafting posts in my mind about stuff I want to write, and yet I never seem to find the time to sit and start. Work, family, hobbies, reading.. everything gets in the way… but does it? Until I removed all distractions from my phone I was also complaining that I didn’t have time to read two books a month.

So today I made the decision to let go of a bunch of Discord communities I’ve been participating in. It was a tough decision because I also get value from it, I learn, share, and help others… but my analysis of the signal vs noise ratio tells me this will be a good decision in the long haul.

I have no blog readers. I have no audience. I have nothing to sell. I want to write just because I like to do it. Not that I’m a great writer, or that aspire to become one and write books. I just like to write on my blog and note down my thoughts about things. Sometimes I like to come back to it and recall past findings and thoughts. Maybe I’m getting old, but I just enjoy quiet time to learn, observe, and reflect. Both reading and writing give me that.

So, today is the day I start and this is the first post of this new phase.

I re-arranged this blog to match this phase, more focus on the blog, and less on my work and projects. Keeping things simple, that’s my way 🙂

Advent of Code Day 2

Reminder: my challenge is to attempt to solve the problem without writing a single line of code. Ideally, just writing an initial prompt and get the whole code in one go. You can see the full source code (and the respective prompts) in my repository at https://github.com/nunodonato/advent-of-code-2021

Part 1

Today I decided to try and push copilot further. Instead of writing my own prompt, with step by step instructions, I basically pasted the challenge instructions directly. The only change needed was the first part where I instruct how to get the data from the input file.

Surprisingly, copilot generated the right solution without any further changes!

Part 2

Part 2 was more challenging, not sure if it’s because it relies on part 1. I tried to do the same, copying and pasting the instructions from part 2 and adding an extra instruction to get the input from the file.

The results were still quite good, but there were a couple of flaws that ended up giving the wrong result.

My struggles for today were to try and avoid these flaws, and it took me quite a number of tries to get it right.

The hardest one was to get copilot to understand that ‘down’ would ADD to the depth and ‘up’ would SUBTRACT. I’m guessing this was probably to the understanding of the model that down is usually a subtraction and up an addition. I tried rewording it, but it kept insisting with these operations.

The other flaw was that it frequently ignored the “aim” variable, even though there was a clear instruction to consider it.

After much tinkering and experimentation, I ended up deleting some lines from the original prompt and slightly changing the words on others. After some trial and error I finally got a working solution (not the 1st proposed one, though).

The final prompt became:

It seems like the submarine can take a series of commands like 'forward 1', 'down 2', or 'up 3':In addition to horizontal position and depth, you'll also need to track a third value, aim, which also starts at 0.

The commands also mean something entirely different than you first thought:
down X increases your aim by X units. 
up X decreases your aim by X units. 
forward X does two things: 
  1. It increases your horizontal position by X units. 
  2. It increases your depth by your aim multiplied by X.

Using this new interpretation of the commands, calculate the horizontal position and depth you would have after following the planned course. What do you get if you multiply your final horizontal position by your final depth?

Advent of Code Day 1

Part 1

The challenge begins. The first puzzle was quite easy to solve, but posed some challenges to write an efficient prompt.

Reminder: my challenge is to attempt to solve the problem without writing a single line of code. Ideally, just writing an initial prompt and get the whole code in one go.
You can see the full source code (and the respective prompts) in my repository at https://github.com/nunodonato/advent-of-code-2021

Although the problem was fairly simple, Copilot struggled with a very specific part of it.

First, I was impressed how easy it was to get it to read from a file which name I didn’t specify directly. I wanted each day to have it’s own input in an “inputs” folder, and have the filenames match. This was easy to accomplish and the solution presented was spot on!

$input = file_get_contents(__DIR__ . '/inputs/' . basename(__FILE__, '.php') . '.txt');

The next part involved a lot of trial and error with the right prompt phrasing. Interestingly the problems with the generated code was always EITHER:

  • looping the array in such a way the it would go out of bounds (trying to read the next position when already in the last, for example) – although this was ok as PHP doesn’t crash, I didn’t accept the solution
  • not incrementing the counter for every find, but instead adding the value of the line to the counter

I had to tinker with this particular line of the prompt until I managed to get it right. And even that was not perfect as the first solution proposed was incorrect. The second, however, was flawless

for ($i = 0; $i < count($input) - 1; $i++) {
    if ($input[$i] < $input[$i + 1]) {
        $counter++;
    }
}

Codex vs Copilot

After I got the problem solved and the solution accepted, I copy&pasted my prompt into OpenAI’s playground using the davinci-codex model.

The solution presented was quite different from what I got, and it was wrong.

I tried a few more, while changing the temperature value, and got a very similar solution(but still not correct) at 0.7

It’s clear that Copilot has some clear advantages over using Codex, as it can present us several solutions at once (and it’s free). I do wonder what are the parameters that it uses! Hopefully will get more insights into it during the challenge.

Part 2

Part two brought a more complex problem. My first attempt was over complicated and copilot was throwing a bunch of useless code.

I re-framed the problem in my mind and decided to approach it in a different way. (important reminder: AI will struggle to solve complex coding problems if you don’t know the steps to solve it yourself)

After simplifying and attacking it from a different angle, I was very close to a solution. Copilot was struggling again with the iteration aspect of it, almost always going out of bounds. I tried different wording but they either made it worse or seemed to be ignored completely.

Finally I tried to write something more verbose and explicit:

// iterate the array until reaching the last-3 element
// store in counter A the sum of three values from the current position
// store in counter B the sum of three values from the next position
// if counter B is greater than counter A, increment the total by one

That gave me a clean and simple solution which I accepted and passed the second part of today’s challenge.

Codex vs Copilot

Using temperature at 0.7 and the exact same prompt, Codex gave me exactly the same solution as copilot did.

Using a telegram bot to help me manage a solar off-grid setup

As some of my reader might know, I live off-the-grid, using solar power for electricity. My setup is quite small, a 9-panel ~2800W array, with 9.9kWh of battery capacity.

However, we do have a lot of electrical needs, since we cook with an induction cook-top, have a dishwasher and an electrical water heater. Back in 2019 I wrote Hacking my way through off-grid survival, in which, amongst other things, I wrote how I used a Raspberry Pi mini computer to poll my inverter and upload useful data to a public server. That way I could easily monitor my system. (Yes, modern inverters already have included cloud solutions). But that is not all, I then coded a small program to add some rudimentary “smartness” to my setup. Using a WiFi-enabled smart power plug, I could automate turning the water tank on or off, based on the solar production, battery capacity and time of day. This still required a lot of time and energy on my part, because I need to very frequently keep an eye on things (except when we have sunny days).

About a month ago I started playing with the idea of creating a personal assistant telegram bot. I wrote about it recently, if you are curious. I was mostly interested in getting reminders and my calendar commitments using an instant-messaging platform. I added a couple more extra features in the meantime. It’s public, you can go check it out and use it for yourself as well.

Then I started to connect the dots, it would be amazing if I could have this bot actually provide me with useful info when I needed it. That way, I could ignore the solar system completely and let the bot handle all the automation.

Being off-grid and depending on solar with limited power storage capacity, means we need to always keep an eye on “what’s coming”. Today we may be having a bright sunny day, but if we know tomorrow we will have less than 1 hour of sun, then we need to change the way we use power today. All this concerns are now delegated to the bot.

In order to get data we could trust, I chose to use Meteoblue’s amazing weather forecasting service. It’s probably one of the world’s most advance weather forecasting, with a high level of detail, extensive set of parameters and high resolution.

I identified 4 main things the bot should be able to do:

  1. Let me know in advance(2 days) of upcoming cloudy and/or rainy days
  2. Give me a forecast of sun hours for a 3-day period
  3. Give me direct access to raw meteograms with cloud layers, temperatures and precipitation
  4. Warn me and my wife in case there is a malfunction or dangerous state with the solar system

Number 1 is perhaps the most useful, as it is the one that allows me to stop worrying about the weather and let the bot handle it for me. I set it up so that everyday at 7am it checks the sun hours and precipitation forecast, and only sends me a message if there is anything worthwhile knowing. If the forecast is good enough to not worry, I won’t receive any message.

Number 2 and 3 are manual operations that I can request at any time. I use these If I’m a bit more picky about the forecasting and want to take a better look myself.

Last, but not least, Number 4 is used to periodically check if everything is OK with the solar production and the batteries. This basically checks two things:

  • solar production is > 0 during the day
  • battery capacity is > 40% (below these we know we have to be more cautious and monitor the batteries more frequently )

Here’s an example of it working when last week I unplugged the panels to replace a damaged cable

This has been great since now I stopped using my phone so much to refresh a page where I had raw data. I’m also more confident that if I’m away for 2 or 3 days my wife will be able to manage things easily without having to worry, or me having to check on things remotely.

Going Forward

All the recent work on the bot has mostly been dedicated to these private features which only me and my wife can access. I’d like to add more to it, so that the automation of the water tank heater could be done by the bot instead of my previous script. The bot, having detailed forecast available at all times can make much better decisions than anything else I’ve done before.

I’ll also introduce some more manual commands to be able to turn things on/off, and have the bot call certain APIs directly, instead of me having to use different apps on the phone to do so.

A Personal Assistant bot for Telegram

My favorite part about being a developer is being able to “scratch-my-own-itch” in a variety of ways 🙂

For a long time I had this dream of developing a digital personal assistant, and finally got started! In these day and age, a personal assistant makes sense to live in a communication app/platform, and Telegram was just perfect for it!

I call it “Ambrósio”, which is a Portuguese name kinda associated with butlers.

For now it has some basic features like reminders, loading up your calendars (from google cal, fastmail, etc), letting you know your daily agenda everyday, quick searching wikipedia, and so on.

But I’m also developing some private (me-only) features in order to have intelligent info regarding my off-grid solar system. I’ll write about that soon.

For now, if you want to give Ambrósio a try, head over to its microsite: https://ambrosio.nunodonato.com. There you can find the link to open a chat in telegram and get started. It also lists all the available commands and sub-commands.

You can’t improve what you don’t track ⏲️

As part of a recent online book club, I spent my last three weeks re-reading Darren Hardy’s “The Compound Effect” on my Kobo eReader.

«No gimmicks. No Hyperbole. No Magic Bullet. The Compound Effect is based on the principle that decisions shape your destiny. Little, everyday decisions will either take you to the life you desire or to disaster by default. Darren Hardy, publisher of Success Magazine, presents The Compound Effect, a distillation of the fundamental principles that have guided the most phenomenal achievements in business, relationships, and beyond. This easy-to-use, step-by-step operating system allows you to multiply your success, chart your progress, and achieve any desire.»

I enjoyed it the first time I read it, but somehow I didn’t get to apply much of the advice. This time I went through it with that intention in mind. I’ve been feeling I should improve some areas of my life and so this was a great opportunity to put it to the test.

What I really like about the compound effect (the effect itself, not the book), is that you don’t need big changes (which often we fail to start or maintain). Rather, it’s all about the small things we can do on a consistent basis.

But we can’t improve what we don’t track. So I bought myself a new journal to exclusively dedicate for tracking progress and planning and setting intentions for my days. (Paper, of course, nothing works better than paper :))

I began by identifying a few key areas where I wanted to improve:

  • spirituality
  • exercise
  • reading/listening to inspiring/spiritual or personal development material
  • gardening work
  • career

For each, I set what I call the minimum acceptable value, which is the target I set myself to achieve before 1st September. After that date, I’m hoping that by tracking daily progress I can improve further. But if not, the compound effect will work its magic on the long run 🙂

Spirituality: 30min /day of meditation + 1 silence day /month
Exercise: 100pushups/day + 20min active exercise/day
Reading/Listening: 20min/day
Gardening Work: 10min/day
Career: 1 educational video/day
Finances: have an emergency fund + begin a long-term savings fund and a savings plan

Although I decided to track daily, my days tend to be quite different from each other. So what I am currently doing is to sum up and do a daily average at the end of each week. I then compare from week to week if I am moving forward or backwards.

Again, these are the minimums I consider essential to maintain regularly. I know I will do some of these much more than the minimum, and others I will have to discipline myself a bit. Besides theses targets, I also identified a few key actions/projects to take on each of these topics to improve them further.

Darren also brings our attention to bad habits which undermine our progress and end up creating bad results in our life (the compound effect acting negatively).
One of the major ones I identified for me was the excessive time wasted in the phone. Now keep in mind I have no instagram, no facebook, no twitter or other social apps on the phone. I read reddit or twitter very rarely by using the phone browser. Still, reading news or discord discussions ended up taking too much time. By using the phone’s own tools, I set limits on daily usage (30min) for a few apps, to make sure I limit screen time. Loading the kobo with some new books, keeping it charged and in my bag, also helps in reading more productive things when unexpected windows of free-time show up.

Apart from this, I also took many ideas from Darren’s daily routine for my own. I’ve been sticking going to bed at 22h30, not wasting so much time in useless activities, and waking up at 5h30-06h00. One of Darren’s morning activities which I’ve also began doing is what he calls ‘Daily Calibration’. I do mine at around 7h30 and it’s a sort of daily review and plan, before we actually start the day. His own daily calibration is about

  • reviewing the top 3 one-year and five-year goals
  • reviewing the quarterly objectives
  • reviewing the top goal for the week and month
  • set three priorities for the day

I especially like the last one, which he calls MVP (most valuable priorities). These are the 3 things that we absolutely must do today. So, even if the rest of the day is total chaos full of surprises, as long as you do those 3, you will at least feel that you moved important pieces in your life/work forward.

I ended up incorporating some of these (and other small tips) on my weekly-review as part of the GTD methodology.

So far this has been great. I love implementing new things, but often abandon them after sometime due to difficulty in keeping up with all the demands. The compound effect makes it simpler and accessible, because it actually prevents you from thinking in big changes. The secret is in all the small, consistent steps.

Looking forward for more 🙂

A class in the clouds – homeschooling with Flight Simulator ✈☁️

This pandemic is running for too long. In our home we all feel a growing desire to move, travel, see places, learn new things…. and adding this to this dad’s passion for airplanes…. well, we got ourselves an idea for a different kind of class! We decided to do a virtual flying tour! Our eldest daughter, Lara, who is 5-and-a-half, was really up to it as well.

So I spent a couple of days brainstorming and planning a few things and eventually settled in a trip to learn about the Azores archipelago, one of two archipelagos of Portugal.
In this first visit I picked the central group of islands, which is the one where the islands are more close together, which is great since we don’t want the trip to take too long (2hrs max).

But don’t be fooled, the plane ride is really a platform to learn about history, geography and so many things about these islands and our world. 🙂

On the eve of our trip I tried to print a map of the islands and the itinerary to follow. But as you might expect, a true printer will never print when you actually need. So forget the printer! We picked up our coloring pencils and made a map ourselves!

Lara chose the sequence we would fly: departure from Terceira, follow north to Graciosa, go down to São Jorge, Pico and finish in Faial

Finally the day came! During the morning the conversations were mostly around the trip we would be doing in the afternoon. So at this point I thought we need to make this even more fun and do some role-play as well!
I made some paper tickets so that this felt like a real trip. I hid one walkie-talkie in the living room, and once in a while I hid somewhere and made some radio announcements regarding boarding times 😂 I don’t even know who is having more fun, me or the kids? ah!

My wife played along and improvised some clothes to look like airport staff and checked the tickets during boarding. Now we are a real airline!

After we all boarded, we set up our equipment, maps and, of course, Lara’s compass! Yes a compass, because this trip won’t have any modern GPS or other navigation aids, we will do it in the old fashioned way following a map and a compass, especially because Lara likes numbers and has been learning about angles lately.
Next to our main screen we have a secondary screen with wikipedia (and other websites) which will provide us with information and knowledge about the places we go to. Oh, and Lara’s globe lamp is also here so we can have a really broad view of where we are flying in planet earth 😃

In case you don’t know, the weather in Azores is really unpredictable and unstable. We were expecting a sunny day but we faced some clouds and lots of wind. But even that was good. Here at home we have been trying to build a paper kite, and one of these days I said we need to build a windsock to help us fly. Windsock? What is it? How does it work? Luckily, airports have plenty of windsocks, so we go and check it out before starting the plane’s engines. A windy day is a good demonstration for a windsock! Now we have a better understanding of what we need to build as well!

As we spend some time talking about the country, the Azores, the island of Terceira, the weather also improved and we got a clearer sky for the rest of the journey. After we took off, Lara learnt what are marinas and ports, what are they used for, and why there are so many in the Azores.

After a shourt tour on the island, we need to get moving because our journey is a long one. Next stop: Graciosa island. For that, we now put the compass to work in order to figure what the heading to follow. Let’s hope we don’t make a mistake or we will end up lost in the middle of the atlantic.

About 10 minutes in we have visual contact with the island of Graciosa. I guess the compass did work and our navigation was correct!

Here we read about lighthouses, something that Lara has heard about but doesn’t remember quite well what it is or what it is for, so we explore a bit more on that topic.

As we approach the airport where we should land, Lara identifies the runway.

Quick enough we are back to our map and compass, checking how to go south towards the island of São Jorge. While we fly amongst the clouds, we read and watch a few interesting things about this island. We ended up with a very cool youtube video that shows a lot of beatiful parts of the nature in São Jorge.

Check it out as well:
https://www.youtube.com/embed/PKkVt8kmvBU
We also read that the north side of the island is characterized by a tall mountain range near the shore. And it is indeed! As we approached we were faced with the tall vertical wall that we struggled to climb, so we thought it would be better to turn east and go around it.

After we went around and started flying towards the airport, Lara noticed something interesting up there in the mountains! What is it?

Oh, those are wind generators, just like we have here near our mountains. They are one of the main sources of energy in Azores.
Not a coincidence, we also learnt about many old fashioned windmills still standing in the islands. I guess its the ancient way of harvesting wind-energy, electricity free!

But Lara wanted to check it out closer, so we looked around for a place to land, and managed to take a really good look at it. While we stopped we got to talk a bit about how a wind generator works.

Back in the air, and with the wind generator park far behind us, we get to experience how long and narrow this island is (it is the longest island in azores!).

Finally we landed and made a quick stop to refuel. Looking to the south of the island, we can already see one of the main attractions of this trip across the sea.

Ready for take-off towards Pico island. With this nice weather we can see it from afar!

We live near the highest mountain range in Portugal, but actually it is not the highest if we consider the islands. Pico, which was a volcano is THE highest mountain in the whole of Portugal. And the fact that it is a volcano makes it far more interesting to learn about 🌋 We took this opportunity to check a comparison chart of the highest mountains in Portugal

We barely made it, but fortunately our plane was strong enough to make a good climb so we could take a peek at the top and learn that volcanoes also extinguish and then “close” when the lava melts.

After going around and checking the volcano, we landed in Pico airport to rest and have a snack! (Yes, because this airline is so cool that offers free snacks!). And we snack with a new view to the mountain 😃

We took off towards our last island: Faial! Because it is so close to Pico the trip was very fast. We got into the island coming from the East, right above the main city of Horta (which gives the airport it’s name). One of the most important cities in Azores, also with a big port and marina.

Here we got to know that Faial island also has its own volcano, with a very beautiful scenery inside it. So of course we had to check it out and take a picture with two volcanoes at the same time 😎

This visit to the second volcano messed up our navigation plans, so we had to go back to Horta, turn-around and get aligned again with the runway. But because our trip was coming to a close, Lara wanted to see the ground once again and so we found a nice empty field with the famous lush-green grass of azores 🐄

And finally, we approach the final airport: Horta.

And so ended our journey, after around 1h30m, plus boarding time 🧳😁

After this we brainstormed so many ideas of places we could visit and learn about, but unfortunately my laptop is too old to be able to visit them. I’m already quite lucky that it can even run this game at all 😅

How I helped a client cut down 90% of server costs with MySQL

First of all, I hope the title isn’t too catchy or misleading. There are no magic secrets here, actually, it’s all pretty common stuff for anyone that has some experience with any DBMS. But that is, in itself, part of point of this article: that sometimes the basic stuff can be overlooked.

(Editorial note: For privacy reasons I changed the names of several things in order to keep the client identity and industry as less-evident as possible)

I won a contract to build a platform for a client. This was to be used internally but also as a way for the client’s clients to access and analyze data. They had a pretty old platform in place that was aging quite fast and lacked useful features. So they hired a company to get them a more modern platform with a flashy UI. Unfortunately, this company didn’t build anything new, rather they used something they already had and made lots of tweaks here and there to try and fit a round peg in a square hole. The end product was interesting at first, but in a short period of time it began to show its weaknesses. So again the need came to actually get something built from the ground up that met the needs of the present and was ready for the future. This is when I come in.