I built an AWS Lambda function to prepare my meals using AI

I built an AWS Lambda function to prepare my meals using AI

ยท

2 min read

This is Day#2 of the #*ServerlessChallenge **challenge, where I'm creating/building serverless apps using different AWS services.*

Short description: An API that accepts a list of food/ingredients that I have and returns meal ideas that I can prepare.

The long/tech description

Using Amazon Bedrock (Jurassic-2 Mid model) to generate some meal ideas and the steps for preparing it after getting the input of the available ingredients and the number of needed meals:

The prompt text is so simple but it's enough to make sure that the output will be as I want, also the max number of tokens is limited to 200 which is enough Don't want to be surprised by the invoice ๐Ÿƒ-

  const command: InvokeModelCommand = new InvokeModelCommand({
    modelId: process.env.BEDROCK_TEXT_MODEL,
    contentType: "application/json",
    accept: "*/*",
    body: JSON.stringify(
      {
        prompt: `Recommend only ${numberOfMeals} meal(s) Which i can make only by using ${ingredients.join(',')}`,
        maxTokens: 200,
        temperature: 0.7,
        topP: 1
      }
    )
  });

The trigger of the lambda function is the endpoint /meals (API Gateway) with the following event schema which has the list of the ingredients & the needed number of meals:

default {
  type: "object",
  properties: {
    ingredients: {type: 'string'},
    count: {type: 'number'}
  },
  required: ['ingredients', 'count']
} as const;
  events: [
    {
      http: {
        method: 'get',
        path: 'meals',
        request: {
          schemas: {
            'application/json': schema,
          },
        },
      },
    },
  ]

So, to wrap that up, simple the function is:

  • Receiving a list of ingredients and the number of meals

  • Invoking the model to get some meal ideas

  • Responding with the ai response

GitHub repo: github.com/Rochdy/mealsRecommender

That was the app of Day#2! looking forward to posting soon about the next app

ย