kahlee.info

Generative AI using AWS

May 2024

Back in 2017 I wrote a blog post about creating serverless apps with AWS Lambda. The project that I created at the time was a random dessert generator which used serverless architecture to generate a random dessert idea. Not all of the ideas generated were good, of course, but the point was to test out end-to-end serverless architecture rather than create world-class desserts.

I had always wanted to extend this project with an automatically generated recipe for the randomly generated dessert. I had played with a couple of ideas, but never built out anything functional. Now AWS has made this possible, and most importantly, accessible, through Amazon Bedrock.

When I learned about Bedrock being available in my region, I spent some time upgrading my random dessert generator to connect to Bedrock, providing the randomly generated dessert in the prompt, and generating a recipe based on the dessert. The original program still uses Python to generate the dessert idea, but the recipe is created with generative AI. I chose the model Amazon Titan Text Lite because of the low cost, and a lightweight model seemed appropriate for this use case.

To make this work, I needed to make the following changes to my environment:

  1. Change the webpage to accommodate the new recipe information (mostly making changes to ensure that multiple clicks wouldn't try to generate multiple recipes, as the generative AI call now takes around 10 seconds while the previous dessert generation was near instant);
  2. Change the Lambda function to make a call to the Bedrock API, receive the response, and incorporate the response into the result;
  3. Enable Bedrock on my AWS account, choosing the most appropriate model for my use case.

This is a simple overview of the architecture:

The results are pretty cool, with the model being able to generate a recipe for most dessert ideas (sometimes it fails, so this has to be handled). The time each call takes isn't prohibitive, but as each request now takes around 10 seconds, I need to handle this on the front-end so that users know something is going on behind the scenes. Give it a try!

At the time of writing, there are certain features of Amazon Bedrock that are not available in my region, such as model customisation and model evaluation. I look forward to trialling these features when they are more generally available, but at this time I couldn't justify the pricing for exploration. In saying that, the AWS News Blog provides a great deal of information about the new features and how they work.

Of course, the big disclaimer is that I cannot guarantee that the recipes that the app generates are correct or delicious, and so far I haven't tried any of the recipes myself. Some of the references it cites also appear to be non-existent. A future enhancement I'll be looking into is the ability to rate and save good recipes, and potentially train a custom model to generate better recipes. This would be beneficial for this app, as trialling different prompts brings unexpected results. For example, this was one result while trying to force the use of "Celsius" over "Fahrenheit" for temperature:

Dessert idea: chocolate and raspberry pie

Here is an ingredient list and recipe for chocolate and raspberry pie using celsius:

Ingredients:

  • 1 packet (10 grams) of vanilla celsius
  • ...

Instructions:

  1. Blend the raspberries, celsius, and milk in a blender.
  2. ...

For now, this was a very interesting exploration into the possibilities of generative AI using AWS. Try the dessert generator.

Diagram made with draw.io. Icons labelled in the diagram for the purpose of describing the tools.