Smol AI tutorial in 5 mins | Build ENTIRE codebase with a single prompt

Written by AI Jason - December 29, 2023


Smol AI Tutorial in 5 Minutes | Build ENTIRE Codebase with a Single Prompt

Ah, what is this? Ah, tight, tight, tight! Yeah! Ah, blue, yellow, pink, whatever, man, just keep bringing me that! Every once in a while, there's a project that makes me feel like we're just scratching the surface with generative AI, and Smol AI is definitely one of those projects. It got more than 8,000 stars on GitHub in just five days, and it is one of the fastest growing open-source AI purchases.

So, what is Smol AI? It is basically an AI that writes code for you. It's different from asking ChatGPT to write some simple code snippet. It actually builds an entire codebase for even very complicated apps. It's almost like having the whole engineering team in your pocket.

And here's a quick example: I ask GPD4 to write a product requirement document for a classic snake game and then pass on those requirements to Smol AI and ask it to build this app. And boom! I just got a fully functional snake game from Smol AI. If I have more requirements, I can just come back and add more stuff and ask it to build multiple things. For example, a simple calculator app, and it will automatically build the app for me.

How does Smol AI work?

When looking through the codebase, it's actually very straightforward. First, they pass the product requirement into a prompt. They will generate the architecture of the app, what different files we need to create. Then, they will pass this list of files, as well as the original product requirement, to another prompt that will generate a list of dependencies. This helps GPD understand the different functions and variables in different files. And in the end, it will run a for loop where it will pass on both the product requirements architecture and the dependencies to a new prompt that will actually write the code for each individual file. That's pretty much it.

But to be honest, at this moment, it's still quite buggy. Most of the time, you will have some bugs or generate some code that requires modification to actually run properly. And I'm going to show you how you can run Smol AI without those bugs step by step.

Setting Up Smol AI

Firstly, let's set it up. You can go to Smol AI's GitHub repository, which I'll post the link in the description, and first, clone this repository on your local machine. Then, open the folder in your Visual Studio Code. There should be a .example.env file. You'll rename this to .env and export your OpenAI API key here.

And before you actually run Smol AI, there is one last step you should do: install Model. Model is basically a cloud computing platform where Smol AI will run. Once that's done, it's pretty much all set. You can open the terminal and run the following command: model-and-prop.

After that, you can add your own prompt, like "Write a web app for to-do." But on the other side, what I would recommend you to do is actually create an MD file, which is basically a documentation, and put all the product requirements here. This way, it'll be easier for you to update the requirements, and you can just run prd.md.

If you just started using Smol AI like this, quite often, you will see some errors. And those errors are due to the rate limit of OpenAI. That's because when Smol AI is running, it will call the OpenAI API multiple times simultaneously, which exceeds the rate limit. But thanks to another YouTuber called Anubis AI, he actually modified the main.py code and added some delay between every API call, so it won't trigger this error. I'll put the modified code in the description below, so you can copy and paste it. Just override the whole main.py file.

Running Smol AI

Now we finish the setup. The next step is to get the product requirement. You can write a simple product requirement by yourself, but to make sure Smol AI actually produces the results you want, you need to add a lot more details to it. What I normally do is go to ChatGPT and ask GPD4 to help me write down the whole product requirement doc, including the core functionalities, interface descriptions, as well as the file structure. Then I can just copy those requirements and put them into the MD file that we just created. And then run model.run(prompt, prd.md).

You can see here, it already identified what kind of files they need to create, as well as breaking down all the shared dependencies, including the variables, data schema, DOM elements, and function names. This whole process is going to take a while. For some complicated apps, it can take like 15 to even 40 minutes.

But here's another tip I want to share. What I noticed is that at this stage, it's still pretty buggy in terms of making sure the function writing in file A is also compatible with file B. So for 90% of the time, the whole codebase it generated didn't work out of the box. However, if I ask it to write everything into just one file, then it magically works 80% to 90% of the time. The code I generate just works out of the box. So in the requirements, I will often say that it should only have one file that includes everything, and that's exactly what I did here.

Now, since it's finished, the files generated will be under the "generated" folder. If we run this, it's a snake game out of the box. It has all the features that keep a snake moving, it has a function to generate food, and it also has a way to keep a score.

Debugging with Smol AI

The last thing I want to mention is that Smol AI not only provides a way to generate code, but it also provides a way to debug the code. So if I add another window here, I can run the command-line model.run(debugger.py). Here's where I can add any errors I saw when running the code. And the same thing, I can put the errors in the prompt directly, but I can also create a debug.md file, and then I can add the errors I saw. And we can run model.run(debugger.py, prompt, debug.md). It will start giving me an analysis of the potential errors and how I can fix them. It's like having both engineers who generate code and a debugger at the same time. That's pretty cool!

Conclusion

Smol AI, as I mentioned, is a little bit buggy. It's not capable of producing very complicated apps out of the box yet. So I don't think it's going to replace a real engineer with its current format. However, as a product designer and product manager, I'm really excited about this. If I want to user test certain product ideas, I can ask Smol AI to build a prototype very quickly and test it with real users for almost zero cost.

On the other side, think about how this whole ecosystem starts to compose on top of each other. We already see AI that can design the user interface, and it's very easy for AI to produce product requirement docs and do research. So I think it's very possible that in the future, we can have a whole AI product team that includes both product managers, product designers, engineers, and QA out of the box and can carry out lots of different experiments for you autonomously. I'm very excited to see what other interesting apps you can ask Smol AI to build. Comment below with any ideas you have!

Frequently Asked Questions

1. Is Smol AI suitable for building complex applications?

No, Smol AI is currently more suited for building simple to moderate complexity applications. It may struggle with highly complex projects.

2. Can Smol AI generate code in multiple programming languages?

Yes, Smol AI is language-agnostic and can generate code in various programming languages, depending on the requirements provided.

3. Can Smol AI handle multi-file projects?

Yes, Smol AI can handle multi-file projects and generate code accordingly. However, it may require additional modifications to ensure compatibility between files.

4. Is Smol AI a replacement for human developers?

No, Smol AI is not intended to replace human developers. It can be a useful tool for quickly prototyping and generating code, but human expertise is still crucial for complex projects and ensuring code quality.

5. Does Smol AI provide debugging capabilities?

Yes, Smol AI provides debugging capabilities. It can analyze potential errors in the generated code and suggest fixes for them.

  1. In today's data-driven world, the ability to extract and utilize information from the web is a crucial skill. Whether you're a data scientist, a business analyst, or just someone looking to gather ins

  2. If you're looking for a unique and underrated side hustle that can potentially earn you over $1,370 per day, then you're in for a treat. This method leverages the power of Canva's AI tools to create s

  3. Building a full-stack application without any coding knowledge and for free might sound too good to be true, but with the right tools, it's entirely possible. In this article, we'll guide you through

  4. In the ever-evolving landscape of artificial intelligence, new models and tools frequently emerge, each promising to revolutionize how we interact with technology. The latest entrant generating buzz i

  5. Is Journalist AI the ultimate AI writing tool you've been searching for? In this article, we delve into an in-depth review of Journalist AI, exploring its features, advantages, and potential drawbacks