The Recipe Agent generates personalized recipe recommendations based on user inputs like ingredients, time, and dietary preferences. It relies on two recipe PDFs stored in a PgVector-powered knowledgebase for fast and efficient searches, then enhances suggestions with web searches using ExaTools.
Create a file ai_recipe_creator_agent.py with the following code:
ai_recipe_creator_agent.py
Copy
Ask AI
from phi.agent import Agentfrom phi.knowledge.pdf import PDFUrlKnowledgeBasefrom phi.vectordb.pgvector import PgVectorfrom phi.tools.exa import ExaToolsdb_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"knowledge_base = PDFUrlKnowledgeBase( urls=[ "https://www.poshantracker.in/pdf/Awareness/MilletsRecipeBook2023_Low%20Res_V5.pdf", "https://www.cardiff.ac.uk/__data/assets/pdf_file/0003/123681/Recipe-Book.pdf", ], vector_db=PgVector(table_name="recipes", db_url=db_url), # we are using PgVector here, you can also use other vector dbs)knowledge_base.load(recreate=False)recipe_agent = Agent( name="RecipeGenie", knowledge_base=knowledge_base, search_knowledge=True, tools=[ExaTools()], markdown=True, instructions=[ "Search for recipes based on the ingredients and time available from the knowledge base.", "Include the exact calories, preparation time, cooking instructions, and highlight allergens for the recommended recipes.", "Always search exa for recipe links or tips related to the recipes apart from knowledge base.", "Provide a list of recipes that match the user's requirements and preferences.", ],)recipe_agent.print_response( "I have potatoes, tomatoes, onions, garlic, ginger, and chicken. Suggest me a quick recipe for dinner", stream=True)