Thoughts on Artificial Intelligence

Artificial Intelligence is probably the most hyped topic at the moment, and for a good reason: it's radically changing the way we work and it will most probably change the way we live.

I know that is a bold statement, but let me show you something. Before dedicating myself to software development, I was an advertising photographer, traveling with a crew of 4/5 people, lots of cameras, lighting, cables, and beautiful models to stunning places to achieve "the perfect shoot". That required a lot of time, money, and effort in general.

Nowadays, we have AI (Artificial Intelligence) systems like DALL-E, Midjourney, Stable Diffusion capable to generate almost any type of image in a few seconds, by just "prompting" them to do it in a textual form, for example:

/imagine [prompt: a stylish girl in a fashionable simple pink dress with the Eiffel Tower in Paris as background]

AI generated girl in pink dress

These impressive results are not limited to images, we have AI models performing incredibly well in:

  • Healthcare Diagnostics: AI is showing lots of potential when it comes to scanning medical images (X-rays, MRIs, ultrasounds, etc...) and supporting doctors in taking decisions or even detecting things that humans are missing.
  • Text Generation / Translation / Classifications: with the rise of NLP (Natural Language Processing) systems, machines went far beyond simple text tagging, or translations; we are using AIs to generate creative content, boost marketing copywriting with data-driven strategies, create sales emails, CVs, summaries, the list is very long.
  • Image and Video Analysis: with a very wide spectrum of use cases from surveillance (detecting suspicious activities), content moderation (detecting harmful/explicit content), support for disabilities (helping people with visual or hearing impairments), self-driving cars.
  • Software Development: AI is already heavily used in the programming field, allowing engineers to code faster and ship higher-quality code. On of the most famous AI "pair programmers" is GitHub Copilot, which of course can count on deep training powered by one of the largest code datasets in the world.
  • Banking and Finance: tasks like fraud detection, risk analysis, credit assessment, and forecasts are becoming much more easy and more efficient thanks to AI.

The list would be very long and with all this evidence on the table, I think is time for everyone who works behind a computer to get familiar with artificial intelligence at various levels.

Why now? What triggered the AI mass adoption?

Artificial intelligence and machine learning have not been invented yesterday, they have been around for many many years. In fact, you may remember your favorite social media using face recognition to automatically tag you into pictures since 2010. But yet, the AI explosion is something we are experiencing right now, with the underlying technology being "packaged" in ready-to-use tools, easy to be enjoyed by non-technical users to perform an incredible variety of tasks.

I believe we own this mass adoption to a combination of factors:

  1. Data availability: let's not forget we need a huge amount of data to train a model. Once upon a time, only big companies could access those datasets, now is easier and way more available to anyone.
  2. Prompt Training: a few years ago, training an AI model was an incredibly complex and expensive task. Nowadays we have pre-trained models which you can fine-tune using prompts, and this makes it way easier to build purpose-driven AI applications.
  3. A mature ecosystem: beyond AI tech, we have a very mature cloud computing ecosystem, API infrastructures that make it possible to deploy and use AI models with a few HTTP calls. Setting up the right hardware, training a model, and make it available on the internet can be out of reach for many, but invoking an API that performs the tasks for us with a few lines of code makes everything more streamlined. Managed AI models as-a-service are popping out every day, like Replicate, Hugging Face, and DeepInfra.

The simplified access to the technology seems to have triggered the creativity of people and organizations who started building all sorts of tools to simplify everyday tasks with AI, in fact, I am very surprised that I am writing this blog post completely by hand!

Prompt Training? Please elaborate!

We just spoke about pre-trained models, but maybe it would have been more precise to say "generally trained models". Past AI models were trained with a very specific purpose in mind, like tagging images, correcting text, predicting numbers and so on. Now we have very large models trained on billions of parameters, that can "act" as your personal accountant, your nutritionist and your lawyer by just changing the prompt.

I personally use LangChain as a framework to develop AI applications - and in case you missed it, I just published a free course to learn LangChain in a fun and simple way. One of the core concepts in LangChain are PromptTemplates, a formatted command that instructs the AI to act in a specific way. Here is a simple example:

prompt_template = """
You are a general practice doctor, please provide me the following information: what's the generic name of Panadol. Do not use technical words, give easy to understand responses. If the answer is not related to medicine, answer "Sorry, this is not my area of expertise".

prompt = PromptTemplate.from_template(template=prompt_template

Using this prompt, the AI will understand we are speaking about pharmaceuticals, provide the correct answer (paracetamol) and limit the risk of hallucinations or confusing the name with synonyms coming from other topics.

We can even "mount" additional knowledge on top of a general-trained model, and make it interact with our custom datasets, by fact "expanding" his knowledge and his capabilities.

Embracing AI in coding

As part of my day-to-day job, I write code and manage development teams for several companies, so I can bring my own real-life experience about the topic. As a matter of fact, Ai is well capable to write awesome code in a fraction of the time compared to a human developer, but under one condition: you need to provide it a well-written prompt.

Do not expect to ask your AI to "build a fully functional payment gateway" and have the product ready to be shipped in 5 minutes. But if you brake down that task in a very specific subset of functionalities, and define the abstractions, the features, and the functions, you can task the AI to write specific pieces of code and it will work out very well. Seeing is believing:


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Stripe\Stripe;
use Stripe\Charge;

class StripeController extends Controller
     * Create a new charge using Stripe API.
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
    public function createCharge(Request $request)
        try {
            // Set your secret key. Remember to switch to your live secret key in production.
            // You can find your API keys in the Stripe Dashboard.

            // Here we're assuming you're passing the amount and currency through the request.
            // Amount should be in the smallest currency unit. E.g., for $10, use 1000 (for cents).
            $charge = Charge::create([
                'amount' => $request->input('amount'),
                'currency' => $request->input('currency', 'usd'), // default to USD
                'source' => $request->input('token'), // obtained with Stripe.js
                'description' => 'Sample Charge',

            // Handle the response (e.g., save to database, return a success message, etc.)
            return response()->json(['success' => true, 'charge' => $charge]);
        } catch (\Exception $e) {
            // Handle the error (e.g., return a custom error message)
            return response()->json(['success' => false, 'error' => $e->getMessage()]);

A sample AI-Generated Laravel Controller to interact with the Stripe API

However, AI in coding is not only about writing code, it also comes very useful in testing or auditing it. By giving the system our own code requirements, like indentation, naming conventions, security rules on escaping sanitizing, we can easily verify if it's compliant, isolate the issues, and let the AI suggest solutions.

Ain't that easy

It's worth remembering that the fact that today we can use artificial intelligence with a relatively low effort doesn't mean there isn't complexity under the hood. What's happening on a deeper level is some very complex math and the "reasoning" processes of artificial intelligence are often beyond the comprehension of their own creators.

Many of the "best-rated brains" on our planet already signed a Pause on AI paper, containing serious worries about where AI can lead us, and unexpected consequences coming from a power we may not be able to control anymore.

Either way, I am excited! Aren't you? :)