Hands-On: Build a Recipe Recommendation AI with CrewAI
19:06

Hands-On: Build a Recipe Recommendation AI with CrewAI

Analytics Vidhya 17.04.2026 38 просмотров 2 лайков

Machine-readable: Markdown · JSON API · Site index

Поделиться Telegram VK Бот
Транскрипт Скачать .md
Анализ с AI
Описание видео
Description: It’s time to code! In our first assignment, we build a Recipe Recommendation System. Learn how to take user inputs (ingredients and dietary restrictions) and use a single CrewAI agent to evaluate, search, and summarize recipes into a step-by-step guide. Chapters: 0:00 Assignment Overview: Recipe AI 1:45 Project Setup: IntelliJ & Environment 2:30 Importing CrewAI Classes 3:45 Defining the Culinary Assistant Agent 5:30 Creating the Filtering & Guidance Tasks 7:40 Executing the Crew & Planning Action 9:15 Final Result & Output Analysis #PythonProject #CrewAI #AICooking #LearnToCode #AIProgramming

Оглавление (7 сегментов)

Assignment Overview: Recipe AI

This is our first assignment. Here I would like you to put in practice some of the things we have learned during the module two especially agents tasks and crew. We're going to do it through the implementation of a very simple recommendation system. Actually this is a recipe recommendation system. Of course it will be very simple and basic. Um, but we will see that it relies on the fact that we're using an LLM under the hood. So, this is a perfect representation of how to exploit the power of an agent. What this uh recommendation system is about, we simply want to get two inputs from the user. One is the main ingredient and the second is a dietary restriction. And what we want to do is to suggest a recipe that matches these two inputs and then provide the step-by-step instructions. That's pretty much it. In particular, we want to collect the information about the recipe. And then we want to do some recipe discovery. So we want to see which recipes are actually matching the inputs that we provide to the agent. uh and then we want to summarize what we have found and then provide the step-by-step instructions. So as you can see there are like a lot of steps that not really deterministic. So because we have to go through different evaluations of the results and perhaps we have to go back if we see that something doesn't fit the initial requirements in this case the

Project Setup: IntelliJ & Environment

two inputs provided by the user. Um so once again this fits very well the use of an agent and the core components of this solution will be the valuation the search of the recipes and then the summarization and we will all do we we're going to do this with a single agent that means that all the things that we see here so the evaluation evaluate search and summarize are going to be tasks that will be assigned to the agent. Once again, let's keep it in mind that we want to keep it as simple as possible. So, we won't go multi- aents for now, but we will focus everything on

Importing CrewAI Classes

one single agent. The actual steps we have to implement basically three. We find the recipes. We filter the recipes based on the inputs we provide. So, the main ingredient and the dietary restrictions. And then we provide the steps to actually cook this recipe. We're going to do this with the help of crew AI of course. And we're going to use only three classes. The crew, the agent, and the tasks. Now we know what to do for this assignment. And it's time to move to our first hands-on project. All right, it's time to code the solution. So we start with creating the file. All right. So first of all before I forget I'm using IntelliJ here and I have this environment already created and inside the environment I have installed QAI and QAI tools. There's nothing that there's nothing more. So I didn't do anything special apart from install installing the packages that I need. But that's pretty much it. If you want you can also use poetry or cond whatever you prefer. And I'm trying to keep also the

Defining the Culinary Assistant Agent

project as simple as possible. I just created a new project with IntelliJ and that's pretty much it. You can basically re replicate all these steps inside Jupyter notebook if you prefer. All right, let's start creating the file. New Python file and we call it recipe recommendation system. Perfect. Now we said that we want to use the agent the tasks the task class and the crew. So we import from crew AI agent task crew. And in addition, we also want to import the LLM class because for this exercise, I want to I misspelled this because for this example, I also want to specify the LLM model that I'm going to use. Before I do that, I leave a comment here because I'm using OpenAI. So I have an open AAI key saved on my bash configuration. So using open AI and also for that you can check the documentation but basically you don't have to do anything special apart from having the key in your bash configuration and then it will be automatically picked by crew AI through as an environment variable. That's pretty much it. So as I said I want to set up an LLM model because I want to explicitly say that I'm using CHP4. This is not mandatory. So if you want you can just use the default model which is still chipd but for the sake of this exercise I prefer to make it explicit.

Creating the Filtering & Guidance Tasks

So we say LLM equal to LLM model equal to GPT4. Perfect. And we also said during the presentation of the assignment that we want to build this recipe recommendation starting from two inputs. One is the main ingredient and one is the dietary restriction. We don't want to treat those as user inputs for now just to make everything kind of more light for this exercise. And we just define two variables. So something like user inputs and we say main ingredient tomato and dietary restrictions shrimps. All right. Now we have these two user inputs which are not really user inputs but instead two variables and it's time to move to the definition of the agent. Defining the agent in defining an agent in QAI is really simple. We just have to use a class agent. We call it culinary assistant agent. And now it's time to instantiate this object. Instantiate the class with the parameters. We need to define the behavior of the agent. First, not mandatory, but as we say, I want to make it explicit. We define the LLM. So, LLM equal to the LLM we defined before. And this is interesting and that's why I want to have this specified explicitly specified inside the agent because if you want you can have different LLMs different LLM models for different agents. So you can have judg LLM model for another agent and so for so on. So it's quite flexible. And now it's time to move to the role. The role of this assistant is just culinary assistant. Here we already see how interesting is to split all the information. So all the characteristics of the agent. So we're not writing everything in one single prompt, but instead we're splitting all these

Executing the Crew & Planning Action

characteristics into multiple parameters. So we start with the role. Now it's time to define the backstory. If you think about the classical approach, backstory is a is a string that appears is a key that appears many times in the prompts because we want the hypothetical agent when we write a prompt, we want this hypothetical agent to have a backstory. So it's really important here is a is a parameter. So we have to define the backstory as a parameter which is once again the attached from the rest of the information that we define for the agent. So the backstory is something like an experienced culinary assistant skill in finding and tailoring recipes. I'm just kind of inventing something that sounds reasonable even though this is an exercise based on ingredients and dietary needs and providing clear step by step cooking instructions. So this is dietary and all right and now we move to the goal. So we didn't tell the agent what's his goal. We just gave the agent some personality. We can say and it's time to tell the agent, okay, what's your goal exactly what you have to do? Not the task, which is something completely deattached from the agent. And it's something we're going to define in a few seconds, but what's the goal of the

Final Result & Output Analysis

agent? The goal is find recipes, filter them to meet dietary, let's say preferences, and guide user through recipe steps. Sounds reasonable. And that's pretty much it. So, we don't have to do anything on top of this. The agent is ready. The agent has a role, a backstory, and a goal. Now it's time to define the tasks that are going to perform by the agent. It's interesting because I see the task as the tasks as something that belong to the agent, but at the same time they belong to the crew in in reality. So is a is not just something that I in my mind based on my experience on crew. It's not that I always assign to always connect to the agent but it's more something that is laying lying between the agent and the crew. We will see what I mean in a few seconds. So we do okay we create the tasks. We start with the first one. We said that in the definition in the during the presentation of the assignment we say that we want to have a way to find and filter the recipes. So we need to find these recipes based on the main ingredient and then we want to filter them based on the dietary restrictions and then we want to select the recipe that is kind of more reasonable for based on our requirements and we want to provide the step-by-step instructions for that recipe. So let's start with the first task which is finding and filtering recipes. So we can say something like find and filter recipes. And now we use the class task. When we define the task, we need to define at least a description, an expected output, and then the agent which is connected to the task. By the way, also I was also thinking that is better if we add something like verbose. This is really useful especially if it's the first time you're working with crew AI because with Verbos we can have a lot of information about the execution what is happening what the agent is kind of thinking somehow which makes everything more clear from our point of view because we can see what's happening under the hood and especially for the sake of this exercise I think is perfect. So let's go back to the agent. As we said, we need to define the description first of all. So description of the task. We need to include the main ingredient. So we can say something like find recipes that use the ingredient main ingredient defined before and filter them to meet dietary restrictions. Perfect. And now we define the expected output. This is also a very powerful way to specify what the what the output will look like instead of wasting too much time trying to describe this as a free text in a huge prompt. There is a big difference here because we can actually define the expected output and we don't have in front of us a huge prompt which is not really scalable here. We can say okay this is the expected output and if something doesn't look fine we can just go back and change this single parameter pretty much what we said before something like one recipe using main ingredient and matching oops and matching data restrictions. Perfect. And now the agent we're going to assign this task to is our only agent because this is a single agent exercise which is our culinary assistant. Once again regarding this expected output why so excited about using this parameter. Well here we're saying let's think about this in the description. We're basically saying hey this is what you have to do. This is the task. The task is about finding the recipes and filter them to meet data restrictions. We're not saying anything about the output. And in a different if you think about the classical approach, you can have everything in one single prompt and say, okay, this description and then I want you to print it in this way. In this case, we're moving to a different parameter and we're saying please only provide one recipe. So we're not saying anything here about providing only one recipe and that matches the dietary restrictions we defined before. So if we want to provide more recipes or change the output, we can just change this expected output which is really powerful and scalable. Now we move to the second task. So our last task which is guide recipe steps. Perfect. Here once again we call the task and once again we have description expected output and the agent we're going to send the task to. Description is just provides step by step instructions for the selected recipe. Perfect. And the expected output stepbystep cooking instructions for the chosen recipe. Easy. And of course the agent is our single agent culinary assistant. And that's it. Now we are done with the agent with the tasks and it's time to put everything together inside our crew. So we move to the crew and we say crew equal to we call the class crew. And inside the crew what we have to specify as we saw in the module two is the agents that are part of the crew the tasks and alo one addition I will say based on my taste which is planning we are going to see what is it. So we do agents equal to cooler assistant. This is a list because usually you want to if whenever you talk about crew AI and crews we're basically you're basically talking about multiple agents. But in this case as we say this is a very basic approach. So we only have one but of course this agents is actually accepting a list. Same for tasks find and filter and then the step by step. All right. and I would like to add something on top of it. Uh this doesn't make this exercise advanced but definitely this is probably the best way to show how planning work works. So with planning we're basically saying which really fits this exercise. We're basically saying okay you have your tasks there is an agent that is going to be assigned to this tasks. So, so the agent that is going to use to pick these tasks. But in addition to that, I would like you to I would like the crews, plan the actions before actually looking into the recipes and print the step by step. So, this planning provide a more kind of robust way to achieve the goal. We don't have to go into the details, but it's not is a nice to have. And then we are pretty much done because it's time to call our crew and kick it off. And that's it. We are basically ready to execute this code. Once again, we decided to use a specific model. We have our user input, which are actually variables. We have our agent, the culinary assistant, and then we have two tasks. one for finding the recipes and filtering and filtering them and one for printing the stepby-step instructions. And now it's time to execute it. So we do Python source recipe recommendation. Let's see if it works. All right. Okay. This is taking some time. So I think everything is fine and it's probably planning sending information to the LLM. We should see something about the first task in a few seconds because thanks to verbose we're going to see the kind of thinking process. Here it is. So now we have agent calling assistant is trying to do this and we have some information about it. So we have all the information that all the things that are going to be done by this agent and now the second task. Okay, perfect. Then the second task which is provide step-by-step instruction and we have some information about it and in the end at the end of the execution we have the final answer which is our step-by-step guide and we get the stepbystep guide on how to make hery tomato sap which I don't know what is it but it sounds delicious I will say and that's pretty much it. This is our final answer. As you saw, we got this really interesting output and really well structured just with 40 lines of code and some comments and most of it is just free strings, free text and that's it. I hope this was clear for each of these concepts. My suggestion is also to check the official documentation so you can go a bit deeper into the classes that we have used. Thank you.

Другие видео автора — Analytics Vidhya

Ctrl+V

Экстракт Знаний в Telegram

Экстракты и дистилляты из лучших YouTube-каналов — сразу после публикации.

Подписаться

Дайджест Экстрактов

Лучшие методички за неделю — каждый понедельник