DEV Community

Cover image for The New Computer: Use Serverless to Build Your First AI-OS App
Dawid Dahl
Dawid Dahl

Posted on • Updated on

The New Computer: Use Serverless to Build Your First AI-OS App

There is no denying some really interesting and groundbreaking things are cooking over at OpenAI.

Why do I say that? The reason is that in recent months they have started to release some things many people didn't fully expect. I believe this is a sign that internally, OpenAI is currently executing on an overarching plan that over the coming years will change the digital landscape completely.

What are some of these things they have released? Examples include GPTs, GPT Actions, and most recently: GPT @-mentions.

GPTs @ mentions

This is simply a way to reference your GPTs—AI chatbots that you can customize on your own—in your current ChatGPT conversation.

Well, you might say, that doesn't sound like such a big deal? And why is so much time being spent on these GPTs? Are they even any good?

Let me show you why it is a big deal.

The Dawn Of A New Computer

Back in the day, there was a little company called Microsoft that revolutionized personal computing. Founded in 1975 by Bill Gates and Paul Allen, Microsoft achieved its big break with MS-DOS, an operating system developed for the IBM PC in 1981. This success paved the way for Windows, which became the dominant operating system worldwide.

Seizing the opportunity in the flourishing era of personal computing, Microsoft's strategic innovations and market adaptability turned it into a tech juggernaut.

OpenAI hypothetical LLM OS


Image of an hypothetical LLM OS by Andrej Karpathy, working at OpenAI.

I believe that what Microsoft did with the release of Windows 1.0 back in 1985, is what OpenAI is gearing up to do in 2024 and beyond: creating a new kind of AI-OS for the next generation of personal computers. This could be as pivotal for our digital interactions as when Bill and Paul revolutionized computing with Windows.

GPTs as AI-OS Apps

So essentially, these GPTs are to the AI-OS, what traditional applications were to Windows; instead of launching an app on your computer, you will be orchestrating AI agents to perform actions on your behalf. And it will be so much more fun and engaging than pressing down 👇🏻 keys on a board or other pieces of plastic.

Instead of being on your own as in the days of PC's past, as I described in a previous article, you will instead be collaborating directly with a host of artificially intelligent beings, not at all unlike how Luke Skywalker is dealing with C-3PO in Star Wars.

C-3PO from Star Wars

But how do you actually create one of these new AI-OS apps? In the next section, I'll guide you through the process using AI to help you build a (AI Application Value Level 2) GPT Action, using serverless functions technology.

The most common way of building a GPT Action today, if you look on ChatGPT-related YouTube content, is Zapier: a no-code platform allowing you to perform actions like sending email or updating your calendar. By using serverless functions instead, you actually won't need to pay Zapier a subscription fee every month!

ℹ️ 1. Even though being a developer helps when building serverless functions, with the help of AI (and a little grit), it's not strictly necessary, as you can learn as you go.

ℹ️ 2. Even though it is called “serverless”, that doesn’t mean there is no server. It just means that we don’t use our own local server; we use some other company’s server in the ☁️.

Using Serverless Functions to Create Your First Proto AI-OS-App

So what shall we build? As a proof-of-concept, let's go for an AI-OS app that should, on the server, generate some ASCII art of a cow that says something. Like this:

ASCII art cow


To create the ASCII art, we'll use cowsay on the server, which is an external library designed for this cowsome purpose.

Then that art should be sent from the server back to the AI-OS app (our GPT), which will then create a beautiful painting drawing inspiration from this ASCII art.

You will need 1) a ChatGPT Plus or Teams account, 2) a free Vercel account and 3) a free GitHub account to build along with me.

Step 1: Set Up The ☁️ Environment

Open up ChatGPT and ask it to generate a serverless function on Vercel.

To get started, use this prompt:

"Could you carefully guide me through creating a serverless function with Vercel using Node, starting by setting up a Next.js project using create-next-app, then writing a basic serverless function in TypeScript, and finally deploying it via the Vercel CLI? Please also explain step-by-step how we link the Vercel project to GitHub."

If you prefer a written guide, you can use this. To see or clone my finished serverless function repository on GitHub, click here.

Vercel's Hobby Plan offers free serverless functions for small projects, with up to 10-second runtime and ample monthly capacity of 100 GB-hours. That means a simple function can be run around 700,000 times a month, for free! No need to pay Zapier every month.

More info on pricing here.

Step 2: Create The Function 🛠️

Now you should have a Next project. Inside the app folder, there is an api folder. Inside that folder, create a new folder and call it something that should be thought of as a spell 🪄✨ we use to activate our function. Let's go for gpt-functions-cowsay, or whatever you'd like. Remember this spell name, we will need it later.

Next, in this spell folder, create a file called route.ts. The folder structure will thus be: app/api/gpt-functions-cowsay/route.ts.

If at any point you feel lost, no worries! Just ask ChatGPT for clarification or help.

Now, request ChatGPT to write the server-side code if it didn't already, to generate a cowsay and return the result. Use this prompt to get started:

"I need help creating a simple serverless function in Next.js that uses the 'cowsay' package. The function should take text from a URL search parameter, make a cow say it, and return this along with the request. Can you guide me through the steps, including necessary TypeScript code, to set up this function?"

If the AI does its job, the code for the function will end up something like this.

import { NextResponse } from "next/server";
import { say } from "cowsay";
import type { NextRequest } from "next/server";

export const GET = (request: NextRequest) => {
  const cowsayText = request.nextUrl.searchParams.get("cowsay") || "";

  return NextResponse.json(
    {
      cowsay: say({ text: cowsayText }),
    },
    {
      status: 200,
    }
  );
};
Enter fullscreen mode Exit fullscreen mode

Paste this code into the route.ts file in the spell folder (gpt-functions-cowsay).

Please note that although this function performs a simple task, in reality, within this server environment, you now wield the full power of software engineering.

That's right. Unlike with Zapier where you are restricted to follow their rules, in here, you can build any tool you want. And through the Actions input the GPTs creation editor, you can hand this tool over to the AI for it to use on your behalf.

Take a moment and just reflect on the vast possibilities. The sk-AI is the limit!

Step 3: Create An OpenAPI Spec 📄

Now, the way we make our GPT aware of our new function so it can use it, is to hand it something called an OpenAPI specification.

Yes, that was not a typo. While OpenAI is the company, OpenAPI is a rulebook for how computer programs talk to each other (APIs).

If you are not a developer, you will have no idea how to write such a specification. But fear not, you can use another GPT called ActionsGPT to do it for you.

Add actions button in gpt editor

  • In the configuration tab of the GTP creator, click the "Create new action" button.
  • In a separate ChatGPT thread, @-mention ActionsGPT.

@ mentioning a gpt

  • Ask it: "I have set up a serverless function in Vercel. What should I do now to get an OpenAPI specification from you?" You could hand it some of the code too.
  • ActionsGPT will tell you to hand it some information.
  • You will give it something like this. (The Base URL you get from your Vercel project.) The prompt doesn't have to be exact, just get the urls and the GET or POST right and describe what your function does. Use this prompt to get started:

"Endpoint URL(s): gpt-functions-cowsay
HTTP Methods: GET
Base URL: gpt-functions-cowsay.vercel.app

When given an input called cowsay, it will take it and make a cowsay out of it. Then it will return the cowsay."

abra cadabra spell function invocation


In Aramaic, "avra kehdabra" means "I will create as I speak". If gpt-functions-cowsay is the kadabra, GET is the abra. Using them both together will cast the function's magic! ✨

  • ActionsGPT will then generate the OpenAPI spec for you.

Step 4: Launch Your GPT! 🚀

Finally, paste the OpenAI specification into the Schema input of the GPT Actions editor. Like this:

GPT actions configuration

If you encounter errors, consult ActionsGPT with your serverless function code at hand. Iteration is key in when building with AI.

Use this free privacy policy generator to create a policy for the GPT action, in case you want your GPT to be public.

Step 5: You're done! ✅

That's it, if OpenAI allows you to save this GPT, that means you did it - you just built your first simple AI-OS app! 👏🏻

This might've seemed daunting, especially for non-developers. And don't worry if you couldn't get it to work on your first try. Because remember, adding an action to a GPT is a Level 2 task in AI software development — it's supposed to be a bit on the tougher side! But also more rewarding and fun to build, if you ask me.

Cow congratulating you

Conclusion

In this guide, you've learned how to create an AI-OS app using serverless technology with our cowsay example. This introductory project showcases the potential for building some truly innovative AI applications.

If you didn't follow along and build it with me, here is the cowtastic Cowsay Creator in action!

gpt allow button for actions


It is all right to press "Allow" here. You can check the Github repo to verify that apart from bad cow art, nothing else bad happens in our serverless action.

OpenAI's latest developments hint at a major shift, similar to when Windows first changed computing. We're seeing the start of a new AI-OS that could change everything, indicating that a future with C-3PO-like companions might be closer than we anticipate.

And while our Cowsay Creator GPT was just for fun and practice, by exploring this, you're already a part of the emerging AI-OS future. Who knows what actually valuable AI-OS apps you'll create next!


Dawid Dahl is a full-stack developer at UMAINARC. In his free time, he enjoys metaphysical ontology, analog synthesizers, consciousness, Huayan and Madhyamika Prasangika philosophy, and being with friends and family.

For those keen to dive deeper into function calling with LLMs, in this article I offer another thorough exploration of the topic.

Top comments (1)

Collapse
 
timetoquite profile image
Eyvind

Impressive work Dawid!
Thx for an interesting read