Building an AI app
Written by Ashton Pieterse
LESSONS WE LEARNED WHILE BUILDING AN APP THAT MAKES USE OF AI
Building an AI app opened our eyes to the complexity of Artificial Intelligence. The purpose was to create something fun and exciting and to start learning the new technologies involved with AI, and quickly it became evident we had a huge learning curve ahead of us.
The saying “There are many ways to skin a cat” comes to mind, in this case the cat being a way to generate recipes with AI that were not only coherent but delicious too.
The first challenge was deciding the technology to use, whether to use OpenAI, or AI services from Azure, AWS or Google.
A couple of days and a few free trials later, we decided to use OpenAI for this specific use case. It was the most cost effective and the language model in our opinion was the best.
Next we had to determine what would be better – training a model from scratch using existing recipes, and then building an app that essentially would continue to learn with each recipe users likes and create more recipes like that, or to rather use an already trained model, relying on its knowledge of existing recipes and food.
The only way to determine the better route was to try both. We had to learn how to train a model on data, and also how to formulate prompts for an existing model.
Let’s sidetrack here on the importance of prompts.
How you formulate prompts is extremely nuanced. We could literally swap two letters around and it would generate a completely different result. We spent weeks tweaking the prompt. One way would give us funky, cool recipe’s that sounded interesting but would taste terrible. However, as we got more specific we managed to get existing and more realistic recipe’s returned.
We learnt that the more wording you had in your prompt often the less successful the result was, and a great way to get what you wanted returned, was to provide an example of the result you want.
Back to the process… In order to train a model we needed vast amounts of data, and we unfortunately didn’t have a collection of tens of thousands of recipes in the format we needed. To solve this, we used AI, essentially getting an already trained GPT-3 model, with randomly assigned ingredients, to generate thousands of recipes. We were then able to use those recipes to essentially train a blank model.
Furthermore, we also learnt that for our use case, using the already trained GPT-3 model was more beneficial and cost efficient than training our own model. In order to train our own model from scratch we would honestly need hundreds of thousands of recipes, specifically formatted to be imported into the model, and that would simply take too much time for the project at hand.
Deciding to use the GPT-3 language model meant prompts were of utmost importance. We had to find the balance of using enough text to get the results we wanted. Using too much text would have resulted in:
The cost of using said prompt being too expensive, and
The prompt being over complicated not yielding the intended result.
Once we nailed the prompt the next challenge was using an AI image generator to create images of the recipes. Challenges we faced were once again with the prompt, formulating it to get images that were of good quality and appropriate. At the beginning we had some crazy things happen, the strangest was a person’s head on a plate of corn for a recipe for “Mexican style Street Food”.
In addition, we learnt that the stable-diffusion model generated better quality images for recipes than the DALL-E model, and also had to learn how to get the best quality image for the lowest price.
Formulating prompts and figuring out the right service and technology use became abundantly important. This determines the success and cost of whatever it is you are trying to achieve with AI.
This app was exciting to build, and learning the nuances involved with AI was an interesting adventure.
AI is the future, and its possibilities and uses are endless. We believe that every business can benefit from AI in one way or another.
The technologies involved can be complex and the methods are certainly not “easy”, but we are glad that we have started the AI journey, and are thrilled to work with it more in the future.
Try the app out for yourself – we’d love to hear your thoughts and feedback! You can download it here in the App Store or here in the Play Store, or alternatively click here for more information about the app and it’s features.