Analytics | Data | Digital Transformation | Artificial Intelligence

Blog

The Lazy, GPT, and Shopping

They say if you want to improve your company’s efficiency, you should hire imaginative lazy people because they will optimize the effort needed. This humble servant doesn’t know how true this is, but she knows it makes her very angry to invest time and effort in doing the same thing twice. So, I must fit into that category. Today I bring you how I managed to avoid going grocery shopping.

Going shopping can be one of the most hated household tasks: you take the car, park, get the cart, turn around because you don’t have coins, rummage through the glove compartment, find a coin, go back for the cart. And you dive straight into the aisles. You go, stroll, buy things you don’t want, don’t buy things you do want because you forget them, fight with some lady for the last cherries, spend valuable minutes searching for the exact package and brand your kids like because you wouldn’t dream of coming home without it. Finally, you face the line to pay. While you wait, you grab something from the surrounding shelves – impulse buying they call it – which you don’t want either, but you’re bored while waiting. You put all your things on the belt where the cashier picks them up at lightning speed and, of course, leaves them all piled up behind the register waiting for you to put them in the reusable bag you didn’t bring but with the same speed. All this while you pay and endure the hate-filled stare of the next person. Then you grab your 12 contaminating bags, transport them with the cart, and load them into the car. Now to return the cart. You pick up the emergency coin you used and if you’re lucky you leave it in the same place you found it for next time. And if not, you’ll have to beg someone, and you know it.

The process has improved over the years: since online shopping became an option, I avoid a couple of crises but still spend too much time searching for references in the web catalog. And I don’t forget as many things since I have the “OK Google, add tomatoes to the shopping list” at a shout. But it’s not enough.

Well. I got tired. We’re in the 21st century, please. A machine can do this. Let’s see, what do we have? We have a website to choose references. We have a shopping list also digital. We have an expert in #webscraping (me, by the way, hehe) who masters #Selenium, #BeautifulSoup and #python.

Let’s build automatic shopping:

Downloading the list from Google Shopping List and feeding it into the supermarket’s reference search was very easy. A few lines of Python, a bit of ingenuity to bypass the supermarket’s anti-bot defenses, and I have a robot that automatically searches the catalog for all the items on the shopping list. But there’s a problem: there are dozens of references for each item on the list. When I search for tomatoes, 29 different references appear. How do I make my robot select exactly what I want?

Let’s reduce the number of references to search through:

The supermarket’s website keeps previous orders so my robot doesn’t have to face the entire catalog, just my “preferred references” list. So, thought and done. Another bit of Selenium, BeautifulSoup, and Python and I have a much narrower list to search through. But several references still come up for each entry. Do I use statistics and make it pick the most frequent one? And here is where the final hurdle appears. The same reference is not always written, described, or priced the same way over time. They change subtly but very frequently! And this is where my automate-shopping crusade ended last time. Until LLM models appeared.

Let’s use #ArtificialIntelligence to find the closest reference:

After some time fighting with the right prompt and different models from #OpenAI (#davinci, #ada, #gpt-3.5 turbo), my robot now “knows” which is the most frequent reference I like to buy from each entry on the list. It can even select the closest one from the entire supermarket catalog. That is, now I write “tomatoes” on my Google Shopping List and my robot picks the correct reference on the supermarket’s website and adds it to the cart. I’ll handle the payment button myself after reviewing what this bot has put in the cart.

Shopping done. In less than 4 minutes each time. I’m a complete lazy person. But now I enjoy a beer on my terrace with the time I used to spend going to the store. Hooray.

And when I feel like it, I’ll extend my robot to other supermarkets’ websites to compare prices and create several optimal carts in terms of cost. And it will only take a bit more Python.

Never underestimate a lazy person.