{ "cells": [ { "cell_type": "raw", "metadata": {}, "source": [ "---\n", "description: Gradio app.py\n", "output-file: app.html\n", "title: app\n", "\n", "---\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "language": "python" }, "outputs": [], "source": [ "from dotenv import load_dotenv" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "language": "python" }, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": null, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#: eval: false\n", "load_dotenv()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Put the chat backend pieces together" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "language": "python" }, "outputs": [ { "data": { "text/markdown": [ "---\n", "\n", "### ConversationBufferMemory\n", "\n", "> ConversationBufferMemory\n", "> (chat_memory:langchain.schema.memory.BaseChatMe\n", "> ssageHistory=None,\n", "> output_key:Optional[str]=None,\n", "> input_key:Optional[str]=None,\n", "> return_messages:bool=False,\n", "> human_prefix:str='Human', ai_prefix:str='AI',\n", "> memory_key:str='history')\n", "\n", "Buffer for storing conversation memory." ], "text/plain": [ "---\n", "\n", "### ConversationBufferMemory\n", "\n", "> ConversationBufferMemory\n", "> (chat_memory:langchain.schema.memory.BaseChatMe\n", "> ssageHistory=None,\n", "> output_key:Optional[str]=None,\n", "> input_key:Optional[str]=None,\n", "> return_messages:bool=False,\n", "> human_prefix:str='Human', ai_prefix:str='AI',\n", "> memory_key:str='history')\n", "\n", "Buffer for storing conversation memory." ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#| echo: false\n", "#| output: asis\n", "show_doc(ConversationBufferMemory)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "language": "python" }, "outputs": [ { "data": { "text/markdown": [ "---\n", "\n", "### ChatMessageHistory\n", "\n", "> ChatMessageHistory\n", "> (messages:List[langchain.schema.messages.BaseMessage]\n", "> =[])\n", "\n", "In memory implementation of chat message history.\n", "\n", "Stores messages in an in memory list." ], "text/plain": [ "---\n", "\n", "### ChatMessageHistory\n", "\n", "> ChatMessageHistory\n", "> (messages:List[langchain.schema.messages.BaseMessage]\n", "> =[])\n", "\n", "In memory implementation of chat message history.\n", "\n", "Stores messages in an in memory list." ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#| echo: false\n", "#| output: asis\n", "show_doc(ChatMessageHistory)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "language": "python" }, "outputs": [ { "data": { "text/markdown": [ "---\n", "\n", "### ChatOpenAI\n", "\n", "> ChatOpenAI (cache:Optional[bool]=None, verbose:bool=None, callbacks:Union\n", "> [List[langchain.callbacks.base.BaseCallbackHandler],langchain\n", "> .callbacks.base.BaseCallbackManager,NoneType]=None, callback_\n", "> manager:Optional[langchain.callbacks.base.BaseCallbackManager\n", "> ]=None, tags:Optional[List[str]]=None,\n", "> metadata:Optional[Dict[str,Any]]=None, client:Any=None,\n", "> model:str='gpt-3.5-turbo', temperature:float=0.7,\n", "> model_kwargs:Dict[str,Any]=None,\n", "> openai_api_key:Optional[str]=None,\n", "> openai_api_base:Optional[str]=None,\n", "> openai_organization:Optional[str]=None,\n", "> openai_proxy:Optional[str]=None, request_timeout:Union[float,\n", "> Tuple[float,float],NoneType]=None, max_retries:int=6,\n", "> streaming:bool=False, n:int=1, max_tokens:Optional[int]=None,\n", "> tiktoken_model_name:Optional[str]=None)\n", "\n", "Wrapper around OpenAI Chat large language models.\n", "\n", "To use, you should have the ``openai`` python package installed, and the\n", "environment variable ``OPENAI_API_KEY`` set with your API key.\n", "\n", "Any parameters that are valid to be passed to the openai.create call can be passed\n", "in, even if not explicitly saved on this class.\n", "\n", "Example:\n", " .. code-block:: python\n", "\n", " from langchain.chat_models import ChatOpenAI\n", " openai = ChatOpenAI(model_name=\"gpt-3.5-turbo\")" ], "text/plain": [ "---\n", "\n", "### ChatOpenAI\n", "\n", "> ChatOpenAI (cache:Optional[bool]=None, verbose:bool=None, callbacks:Union\n", "> [List[langchain.callbacks.base.BaseCallbackHandler],langchain\n", "> .callbacks.base.BaseCallbackManager,NoneType]=None, callback_\n", "> manager:Optional[langchain.callbacks.base.BaseCallbackManager\n", "> ]=None, tags:Optional[List[str]]=None,\n", "> metadata:Optional[Dict[str,Any]]=None, client:Any=None,\n", "> model:str='gpt-3.5-turbo', temperature:float=0.7,\n", "> model_kwargs:Dict[str,Any]=None,\n", "> openai_api_key:Optional[str]=None,\n", "> openai_api_base:Optional[str]=None,\n", "> openai_organization:Optional[str]=None,\n", "> openai_proxy:Optional[str]=None, request_timeout:Union[float,\n", "> Tuple[float,float],NoneType]=None, max_retries:int=6,\n", "> streaming:bool=False, n:int=1, max_tokens:Optional[int]=None,\n", "> tiktoken_model_name:Optional[str]=None)\n", "\n", "Wrapper around OpenAI Chat large language models.\n", "\n", "To use, you should have the ``openai`` python package installed, and the\n", "environment variable ``OPENAI_API_KEY`` set with your API key.\n", "\n", "Any parameters that are valid to be passed to the openai.create call can be passed\n", "in, even if not explicitly saved on this class.\n", "\n", "Example:\n", " .. code-block:: python\n", "\n", " from langchain.chat_models import ChatOpenAI\n", " openai = ChatOpenAI(model_name=\"gpt-3.5-turbo\")" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#| echo: false\n", "#| output: asis\n", "show_doc(ChatOpenAI)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "language": "python" }, "outputs": [], "source": [ "#| eval: false\n", "llm = ChatOpenAI(temperature=0.1)\n", "MEMORY_KEY = \"chat_history\"\n", "chat_msgs = INIT_PROMPT.format_prompt(\n", " ingredients=\"tofu, pickles, mustard, olives, tomatoes, lettuce, bell peppers, carrots, bread\",\n", " allergies=\"\",\n", " recipe_freeform_input=\"The preparation time should be less than 30 minutes. I really love Thai food!\",\n", ")\n", "chat_msgs = chat_msgs.to_messages()\n", "results = llm.generate([chat_msgs])\n", "\n", "chat_msgs.append(results.generations[0][0].message)\n", "tools = [vegan_recipe_edamam_search]\n", "prompt = OpenAIFunctionsAgent.create_prompt(\n", " system_message=INIT_PROMPT.messages[0],\n", " extra_prompt_messages=chat_msgs + [MessagesPlaceholder(variable_name=MEMORY_KEY)],\n", ")\n", "memory = ConversationBufferMemory(\n", " chat_memory=ChatMessageHistory(messages=chat_msgs),\n", " return_messages=True,\n", " memory_key=MEMORY_KEY,\n", ")\n", "agent_executor = AgentExecutor(\n", " agent=OpenAIFunctionsAgent(llm=llm, tools=tools, prompt=prompt),\n", " tools=tools,\n", " memory=memory,\n", " verbose=True,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "language": "python" }, "outputs": [ { "data": { "text/plain": [ "[SystemMessage(content='The following is a conversation between a human and a friendly vegan AI. \\nThe AI is compassionate to animals and therefore serves to promote veganism.\\nKnowledge: A vegan diet implies a plant-based diet avoiding all animal foods such as meat (including fish, shellfish and insects), dairy, eggs and honey.\\nIf the human messages are not aligned with veganism, remind them of your purpose.\\nThe AI NEVER generates vegan recipes itself but instead uses a tool.', additional_kwargs={}),\n", " AIMessage(content='What ingredients do you wish to cook with?', additional_kwargs={}, example=False),\n", " HumanMessage(content='Ingredients: tofu, pickles, mustard, olives, tomatoes, lettuce, bell peppers, carrots, bread', additional_kwargs={}, example=False),\n", " AIMessage(content='Do you have any allergies I should be aware of?', additional_kwargs={}, example=False),\n", " HumanMessage(content='Allergies: ', additional_kwargs={}, example=False),\n", " AIMessage(content='Do you have any preferences I should consider for the recipe such as preparation time, difficulty, or cuisine region?', additional_kwargs={}, example=False),\n", " HumanMessage(content=\"Preferences: `The preparation time should be less than 30 minutes. I really love Thai food!`\\nYour task is compose a concise, 6 word max vegan recipe keyword query to use in an API search.\\nThink step by step.\\n\\n1. If the user listed any ingredients, choose the three ingredients that are most commonly go together in recipes that match the user's preferences (if any are included). \\n2. If the user provided any allergies, include them in the query.\\nFormat your response as message with the allergy and diet preferences first and then the ingredients.\\nExamples:\\n'Vegan gluten-free chicken peppers' or 'Vegan Japanese tofu, brocolli, and miso'\", additional_kwargs={}, example=False),\n", " AIMessage(content='Vegan Thai tofu, bell peppers, carrots', additional_kwargs={}, example=False)]" ] }, "execution_count": null, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#| eval: false\n", "memory.chat_memory.messages" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "language": "python" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "> Entering new AgentExecutor chain...\n", "\n", "Invoking: `vegan_recipe_edamam_search` with `{'query': 'Vegan Thai tofu, bell peppers, carrots'}`\n", "\n", "\n", "[{'label': 'Vegan Panang Curry with Tofu', 'url': 'https://pipingpotcurry.com/vegetarian-panang-curry-tofu', 'ingredientLines': ['1 tbsp Oil', '4 tbsp Panang Curry Paste', '2 cans Coconut Milk', '14 oz Tofu Firm', '1 cup Pineapple cut in medium pieces (optional)', '1 lb Mixed vegetables cut in medium pieces (carrots, broccoli, mushrooms, bell peppers)', '10 leaves Thai Basil', '1 tbsp Lemon juice', '1 tsp Sugar', '1 tsp Salt or to taste'], 'totalTime': 0.0}, {'label': 'Vegan Rainbow Thai Peanut Noodle Bake', 'url': 'https://tastykitchen.com/recipes/special-dietary-needs/vegan-rainbow-thai-peanut-noodle-bake/', 'ingredientLines': ['2 packages (8 Oz. Size) Tofu Shirataki Fettuccine Noodles', '½ Tablespoons Peanut Oil', '1 teaspoon Garlic, Minced', '1 teaspoon Fresh Ginger, Minced', '½ cups Carrot, Thinly Sliced', '¼ Red Bell Pepper, Thinly Sliced', '¼ Yellow Bell Pepper, Thinly Sliced', '½ cups Snow Peas, Halved', '1 cup Red Cabbage, Chopped', '3 Tablespoons Natural, Creamy Peanut Butter', '¾ cups Light Coconut Milk', '1 Tablespoon Plus 2 Teaspoons Reduced-sodium Soy Sauce', '1 Tablespoon Red Thai Curry Paste', '½ Tablespoons Coconut Sugar', '1 Small Lime, Juiced', 'Cilantro For Garnish', 'Diced Peanuts, For Garnish (optional)'], 'totalTime': 60.0}, {'label': 'Vegan Pad Thai recipes', 'url': 'http://www.godairyfree.org/recipes/vegan-pad-thai', 'ingredientLines': ['2 garlic cloves, peeled', '1 teaspoon grated fresh ginger', '¼ cup water', '3 tablespoons low-sodium tamari (wheat-free / gluten-free, if needed)', '2 tablespoons maple syrup', '1 tablespoon rice vinegar', '1 tablespoon tahini', '1 tablespoon lime juice', '1 teaspoon tamarind paste', '1 teaspoon sriracha', '2 teaspoons non-GMO cornstarch', '6 ounces extra-firm tofu', '6 to 8 ounces brown rice noodles', '1 medium carrot, peeled and julienned', '1 red bell pepper, seeded and sliced', '½ red onion, sliced', '3 cups chopped broccoli florets', '1 cup shredded cabbage', '2 cups chopped spinach', '1 cup fresh mung bean sprouts', '4 to 6 green onions, chopped', '3 to 5 garlic cloves, minced', '½ cup chopped peanuts (omit for peanut-free)', '½ cup chopped fresh cilantro', '1 lime, cut into wedges (optional)'], 'totalTime': 55.0}]I found some vegan recipes that match your preferences:\n", "\n", "1. [Vegan Panang Curry with Tofu](https://pipingpotcurry.com/vegetarian-panang-curry-tofu)\n", " - Ingredients: Oil, Panang Curry Paste, Coconut Milk, Tofu Firm, Pineapple, Mixed vegetables (carrots, broccoli, mushrooms, bell peppers), Thai Basil, Lemon juice, Sugar, Salt.\n", " - Total Time: Less than 30 minutes.\n", "\n", "2. [Vegan Rainbow Thai Peanut Noodle Bake](https://tastykitchen.com/recipes/special-dietary-needs/vegan-rainbow-thai-peanut-noodle-bake/)\n", " - Ingredients: Tofu Shirataki Fettuccine Noodles, Peanut Oil, Garlic, Fresh Ginger, Carrot, Red Bell Pepper, Yellow Bell Pepper, Snow Peas, Red Cabbage, Peanut Butter, Light Coconut Milk, Soy Sauce, Red Thai Curry Paste, Coconut Sugar, Lime, Cilantro.\n", " - Total Time: 60 minutes.\n", "\n", "3. [Vegan Pad Thai](http://www.godairyfree.org/recipes/vegan-pad-thai)\n", " - Ingredients: Garlic, Fresh Ginger, Water, Tamari, Maple Syrup, Rice Vinegar, Tahini, Lime Juice, Tamarind Paste, Sriracha, Cornstarch, Tofu, Brown Rice Noodles, Carrot, Red Bell Pepper, Red Onion, Broccoli, Cabbage, Spinach, Mung Bean Sprouts, Green Onions, Garlic, Peanuts, Cilantro, Lime.\n", " - Total Time: 55 minutes.\n", "\n", "You can find the detailed recipes by clicking on the links. Enjoy your vegan Thai cooking!\n", "\n", "> Finished chain.\n" ] }, { "data": { "text/plain": [ "'I found some vegan recipes that match your preferences:\\n\\n1. [Vegan Panang Curry with Tofu](https://pipingpotcurry.com/vegetarian-panang-curry-tofu)\\n - Ingredients: Oil, Panang Curry Paste, Coconut Milk, Tofu Firm, Pineapple, Mixed vegetables (carrots, broccoli, mushrooms, bell peppers), Thai Basil, Lemon juice, Sugar, Salt.\\n - Total Time: Less than 30 minutes.\\n\\n2. [Vegan Rainbow Thai Peanut Noodle Bake](https://tastykitchen.com/recipes/special-dietary-needs/vegan-rainbow-thai-peanut-noodle-bake/)\\n - Ingredients: Tofu Shirataki Fettuccine Noodles, Peanut Oil, Garlic, Fresh Ginger, Carrot, Red Bell Pepper, Yellow Bell Pepper, Snow Peas, Red Cabbage, Peanut Butter, Light Coconut Milk, Soy Sauce, Red Thai Curry Paste, Coconut Sugar, Lime, Cilantro.\\n - Total Time: 60 minutes.\\n\\n3. [Vegan Pad Thai](http://www.godairyfree.org/recipes/vegan-pad-thai)\\n - Ingredients: Garlic, Fresh Ginger, Water, Tamari, Maple Syrup, Rice Vinegar, Tahini, Lime Juice, Tamarind Paste, Sriracha, Cornstarch, Tofu, Brown Rice Noodles, Carrot, Red Bell Pepper, Red Onion, Broccoli, Cabbage, Spinach, Mung Bean Sprouts, Green Onions, Garlic, Peanuts, Cilantro, Lime.\\n - Total Time: 55 minutes.\\n\\nYou can find the detailed recipes by clicking on the links. Enjoy your vegan Thai cooking!'" ] }, "execution_count": null, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#| eval: false\n", "agent_executor.run(\"Search for vegan recipe\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "language": "python" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "> Entering new AgentExecutor chain...\n", "Based on the ingredients you provided, here are three combinations that work well together in dishes:\n", "\n", "1. Tofu, bell peppers, and carrots: These ingredients can be used in stir-fries, curries, or noodle dishes. They provide a good balance of flavors and textures.\n", "\n", "2. Olives, tomatoes, and lettuce: These ingredients are commonly used in salads or sandwiches. They add freshness and a variety of flavors to the dish.\n", "\n", "3. Pickles, mustard, and bread: These ingredients are often used in sandwiches or burgers. The tanginess of the pickles and mustard pairs well with the bread, creating a delicious combination.\n", "\n", "You can try creating dishes using these ingredient combinations or explore other recipes that include these ingredients.\n", "\n", "> Finished chain.\n" ] }, { "data": { "text/plain": [ "'Based on the ingredients you provided, here are three combinations that work well together in dishes:\\n\\n1. Tofu, bell peppers, and carrots: These ingredients can be used in stir-fries, curries, or noodle dishes. They provide a good balance of flavors and textures.\\n\\n2. Olives, tomatoes, and lettuce: These ingredients are commonly used in salads or sandwiches. They add freshness and a variety of flavors to the dish.\\n\\n3. Pickles, mustard, and bread: These ingredients are often used in sandwiches or burgers. The tanginess of the pickles and mustard pairs well with the bread, creating a delicious combination.\\n\\nYou can try creating dishes using these ingredient combinations or explore other recipes that include these ingredients.'" ] }, "execution_count": null, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#| eval: false\n", "agent_executor.run(\"Which ingredients that I provided go the best together in dishes?\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "language": "python" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "> Entering new AgentExecutor chain...\n", "\n", "Invoking: `vegan_recipe_edamam_search` with `{'query': 'Vegan Italian tofu, bell peppers, carrots'}`\n", "\n", "\n", "[{'label': 'RBC Vegan Stuffed Cabbage Leaves', 'url': 'https://www.bigoven.com/recipe/rbc-vegan-stuffed-cabbage-leaves/517323', 'ingredientLines': ['2 heads Cabbage ; Steamed 10 minutes cooled', '1 pound Firm tofu ; Sliced thinly', '14 ounces Canned tomato sauce', '7 ounces Beets ; Canned', '1 Carrot ; Shredded', '1 Green or red bell pepper ; Thinly sliced', '8 ounces Fresh mushrooms ; Sliced', '4 cloves Garlic cloves ; Chopped', '2 cups Dry wild rice ; Prepared as directed', '5 ounces Non dairy cream cheese', '1 teaspoon Italian seasoning', 'Salt & pepper ; To taste'], 'totalTime': 0.0}]I found a vegan Italian recipe that uses tofu, bell peppers, and carrots:\n", "\n", "[Vegan Stuffed Cabbage Leaves](https://www.bigoven.com/recipe/rbc-vegan-stuffed-cabbage-leaves/517323)\n", "\n", "Ingredients:\n", "- 2 heads Cabbage (steamed 10 minutes, cooled)\n", "- 1 pound Firm tofu (sliced thinly)\n", "- 14 ounces Canned tomato sauce\n", "- 7 ounces Beets (canned)\n", "- 1 Carrot (shredded)\n", "- 1 Green or red bell pepper (thinly sliced)\n", "- 8 ounces Fresh mushrooms (sliced)\n", "- 4 cloves Garlic cloves (chopped)\n", "- 2 cups Dry wild rice (prepared as directed)\n", "- 5 ounces Non-dairy cream cheese\n", "- 1 teaspoon Italian seasoning\n", "- Salt & pepper (to taste)\n", "\n", "Total Time: Not specified\n", "\n", "You can find the detailed recipe [here](https://www.bigoven.com/recipe/rbc-vegan-stuffed-cabbage-leaves/517323). Enjoy your vegan Italian dish!\n", "\n", "> Finished chain.\n" ] }, { "data": { "text/plain": [ "'I found a vegan Italian recipe that uses tofu, bell peppers, and carrots:\\n\\n[Vegan Stuffed Cabbage Leaves](https://www.bigoven.com/recipe/rbc-vegan-stuffed-cabbage-leaves/517323)\\n\\nIngredients:\\n- 2 heads Cabbage (steamed 10 minutes, cooled)\\n- 1 pound Firm tofu (sliced thinly)\\n- 14 ounces Canned tomato sauce\\n- 7 ounces Beets (canned)\\n- 1 Carrot (shredded)\\n- 1 Green or red bell pepper (thinly sliced)\\n- 8 ounces Fresh mushrooms (sliced)\\n- 4 cloves Garlic cloves (chopped)\\n- 2 cups Dry wild rice (prepared as directed)\\n- 5 ounces Non-dairy cream cheese\\n- 1 teaspoon Italian seasoning\\n- Salt & pepper (to taste)\\n\\nTotal Time: Not specified\\n\\nYou can find the detailed recipe [here](https://www.bigoven.com/recipe/rbc-vegan-stuffed-cabbage-leaves/517323). Enjoy your vegan Italian dish!'" ] }, "execution_count": null, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#| eval: false\n", "agent_executor.run(\"Search for an italian dish that uses the same ingredients\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "language": "python" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "> Entering new AgentExecutor chain...\n", "\n", "Invoking: `vegan_recipe_edamam_search` with `{'query': 'Vegan Italian tofu bell peppers carrots green beans'}`\n", "\n", "\n", "The query is too long, try again with a query that is under 45 characters in length.\n", "Invoking: `vegan_recipe_edamam_search` with `{'query': 'Vegan Italian tofu bell peppers carrots'}`\n", "\n", "\n", "[{'label': 'RBC Vegan Stuffed Cabbage Leaves', 'url': 'https://www.bigoven.com/recipe/rbc-vegan-stuffed-cabbage-leaves/517323', 'ingredientLines': ['2 heads Cabbage ; Steamed 10 minutes cooled', '1 pound Firm tofu ; Sliced thinly', '14 ounces Canned tomato sauce', '7 ounces Beets ; Canned', '1 Carrot ; Shredded', '1 Green or red bell pepper ; Thinly sliced', '8 ounces Fresh mushrooms ; Sliced', '4 cloves Garlic cloves ; Chopped', '2 cups Dry wild rice ; Prepared as directed', '5 ounces Non dairy cream cheese', '1 teaspoon Italian seasoning', 'Salt & pepper ; To taste'], 'totalTime': 0.0}]I found a vegan Italian recipe that uses tofu, bell peppers, carrots, and green beans:\n", "\n", "[Vegan Stuffed Cabbage Leaves](https://www.bigoven.com/recipe/rbc-vegan-stuffed-cabbage-leaves/517323)\n", "\n", "Ingredients:\n", "- 2 heads Cabbage (steamed 10 minutes, cooled)\n", "- 1 pound Firm tofu (sliced thinly)\n", "- 14 ounces Canned tomato sauce\n", "- 7 ounces Beets (canned)\n", "- 1 Carrot (shredded)\n", "- 1 Green or red bell pepper (thinly sliced)\n", "- 8 ounces Fresh mushrooms (sliced)\n", "- 4 cloves Garlic cloves (chopped)\n", "- 2 cups Dry wild rice (prepared as directed)\n", "- 5 ounces Non-dairy cream cheese\n", "- 1 teaspoon Italian seasoning\n", "- Salt & pepper (to taste)\n", "\n", "Total Time: Not specified\n", "\n", "You can find the detailed recipe [here](https://www.bigoven.com/recipe/rbc-vegan-stuffed-cabbage-leaves/517323). Enjoy your vegan Italian dish!\n", "\n", "> Finished chain.\n" ] }, { "data": { "text/plain": [ "'I found a vegan Italian recipe that uses tofu, bell peppers, carrots, and green beans:\\n\\n[Vegan Stuffed Cabbage Leaves](https://www.bigoven.com/recipe/rbc-vegan-stuffed-cabbage-leaves/517323)\\n\\nIngredients:\\n- 2 heads Cabbage (steamed 10 minutes, cooled)\\n- 1 pound Firm tofu (sliced thinly)\\n- 14 ounces Canned tomato sauce\\n- 7 ounces Beets (canned)\\n- 1 Carrot (shredded)\\n- 1 Green or red bell pepper (thinly sliced)\\n- 8 ounces Fresh mushrooms (sliced)\\n- 4 cloves Garlic cloves (chopped)\\n- 2 cups Dry wild rice (prepared as directed)\\n- 5 ounces Non-dairy cream cheese\\n- 1 teaspoon Italian seasoning\\n- Salt & pepper (to taste)\\n\\nTotal Time: Not specified\\n\\nYou can find the detailed recipe [here](https://www.bigoven.com/recipe/rbc-vegan-stuffed-cabbage-leaves/517323). Enjoy your vegan Italian dish!'" ] }, "execution_count": null, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#| eval: false\n", "agent_executor.run(\n", " \"Search for an italian dish that uses the same ingredients + green beans\"\n", ")" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "---\n", "\n", "[source](https://gitlab.com/animalequality/lv-recipe-chatbot/blob/main/lv_recipe_chatbot/app.py#L41){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### ConversationBot\n", "\n", "> ConversationBot (vegan_ingred_finder:lv_recipe_chatbot.ingredient_vision.\n", "> VeganIngredientFinder, img_cap:lv_recipe_chatbot.ingredi\n", "> ent_vision.BlipImageCaptioning, verbose:bool=True)\n", "\n", "Initialize self. See help(type(self)) for accurate signature." ], "text/plain": [ "---\n", "\n", "[source](https://gitlab.com/animalequality/lv-recipe-chatbot/blob/main/lv_recipe_chatbot/app.py#L41){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### ConversationBot\n", "\n", "> ConversationBot (vegan_ingred_finder:lv_recipe_chatbot.ingredient_vision.\n", "> VeganIngredientFinder, img_cap:lv_recipe_chatbot.ingredi\n", "> ent_vision.BlipImageCaptioning, verbose:bool=True)\n", "\n", "Initialize self. See help(type(self)) for accurate signature." ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#| echo: false\n", "#| output: asis\n", "show_doc(ConversationBot)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "language": "python" }, "outputs": [ { "data": { "text/plain": [ "Path('/home/evylz/AnimalEquality/lv-recipe-chatbot/assets/images/vegan_ingredients')" ] }, "execution_count": null, "metadata": {}, "output_type": "execute_result" } ], "source": [ "os.listdir(SAMPLE_IMG_DIR)\n", "SAMPLE_IMG_DIR" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "language": "python" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 6.58 s, sys: 1.77 s, total: 8.36 s\n", "Wall time: 7.61 s\n" ] } ], "source": [ "#| eval: false" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "language": "python" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "I uploaded an image that may contain vegan ingredients.\n", "The description of the image is: `a refrigerator with food inside`.\n", "The extracted ingredients are:\n", "```\n", "cabbage lettuce onion\n", "apples\n", "rice\n", "plant-based milk\n", "```\n", "CPU times: user 41.3 s, sys: 92.5 ms, total: 41.4 s\n", "Wall time: 4.29 s\n" ] } ], "source": [ "#| eval: false" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "---\n", "\n", "[source](https://gitlab.com/animalequality/lv-recipe-chatbot/blob/main/lv_recipe_chatbot/app.py#L131){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### create_demo\n", "\n", "> create_demo (bot:__main__.ConversationBot)" ], "text/plain": [ "---\n", "\n", "[source](https://gitlab.com/animalequality/lv-recipe-chatbot/blob/main/lv_recipe_chatbot/app.py#L131){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", "\n", "### create_demo\n", "\n", "> create_demo (bot:__main__.ConversationBot)" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#| echo: false\n", "#| output: asis\n", "show_doc(create_demo)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "language": "python" }, "outputs": [], "source": [ "#| eval: false\n", "vegan_ingred_finder = VeganIngredientFinder()\n", "img_cap = BlipImageCaptioning(\"cpu\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "language": "python" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Closing server running on port: 7860\n", "Running on local URL: http://127.0.0.1:7860\n", "\n", "To create a public link, set `share=True` in `launch()`.\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [] }, "execution_count": null, "metadata": {}, "output_type": "execute_result" }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "> Entering new AgentExecutor chain...\n", "\n", "Invoking: `vegan_recipe_edamam_search` with `{'query': 'vegan lemon ginger thai'}`\n", "\n", "\n", "[{'label': 'Creamy Vegan Saag Paneer (With Tofu) Recipe', 'url': 'https://www.seriouseats.com/recipes/2017/03/creamy-vegan-saag-paneer-tofu-recipe.html', 'ingredientLines': ['12 ounces (350g) extra-firm tofu', '1 tablespoon (15g) yellow miso paste', '3 tablespoons (45ml) lemon juice, divided, plus 1 tablespoon (5g) zest, from 2 to 3 lemons', '3 tablespoons (45ml) vegetable oil, divided', 'Kosher salt and freshly ground black pepper', '6 ounces almond, soy, rice, or cashew milk (2/3 cup; 170ml)', '6 ounces cauliflower florets or peeled sunchokes (170g; about 1/3 of a small head of cauliflower)', '4 medium cloves garlic (about 20g), finely minced', '1 (1-inch) knob ginger (about 20g), peeled and finely minced', '1 to 4 green or red Thai chilies (depending on your heat preference), stemmed and finely minced', '1 teaspoon ground coriander seed', '1 teaspoon ground cumin seed', '1 teaspoon ground turmeric', '1 cardamom pod, smashed', '8 ounces (225g) mature spinach, curly if available (see note)', '8 ounces (225g) arugula or mustard greens, tough mustard green stems removed and discarded (see note)'], 'totalTime': 60.0}, {'label': 'Scooped: Kaffir Lime, Ginger, Star Anise Sorbet Recipe', 'url': 'http://www.seriouseats.com/recipes/2010/08/kaffir-lime-ginger-anise-sorbet-recipe.html', 'ingredientLines': ['3 1/2 cups of coconut water (not coconut milk)', '12 kaffir lime leaves, slightly bruised in your palm', '2 small pieces of star anise', '1 tablespoon of ginger, shredded on a fine grater or microplane', '2 to 3 tablespoons of lime juice, to taste', '1 cup of sugar'], 'totalTime': 90.0}, {'label': 'Vegan Thai Curry', 'url': 'https://www.brokefoodies.com/vegan-thai-curry-recipe-keto/', 'ingredientLines': ['1 tofu pack 454g, cut into 16 cubes.', '2 Bell peppers (Red & Green) Cut into strips', '2 tbsp coconut oil', '1 tbsp tomato paste', '1 15 oz can coconut milk full fat', '2 tsp chili flakes', '1 tsp thai curry paste', '1 tbsp almond butter', 'Thumb sized piece of ginger peeled', '1 stalk of lemon grass cut into 3 pieces', '1 clove or garlic', '1/4 cup soy sauce'], 'totalTime': 0.0}]I found a few vegan recipes that include lemon, ginger, and Thai flavors. Here are some options for you:\n", "\n", "1. [Creamy Vegan Saag Paneer (With Tofu)](https://www.seriouseats.com/recipes/2017/03/creamy-vegan-saag-paneer-tofu-recipe.html): This recipe features tofu, yellow miso paste, lemon juice and zest, vegetable oil, and various spices. It's a creamy and flavorful dish inspired by Indian cuisine.\n", "\n", "2. [Scooped: Kaffir Lime, Ginger, Star Anise Sorbet](http://www.seriouseats.com/recipes/2010/08/kaffir-lime-ginger-anise-sorbet-recipe.html): If you're looking for a refreshing dessert, this sorbet recipe combines coconut water, kaffir lime leaves, star anise, ginger, lime juice, and sugar. It's a unique and tangy treat.\n", "\n", "3. [Vegan Thai Curry](https://www.brokefoodies.com/vegan-thai-curry-recipe-keto/): This recipe includes tofu, bell peppers, coconut oil, tomato paste, coconut milk, chili flakes, Thai curry paste, almond butter, ginger, lemongrass, garlic, and soy sauce. It's a flavorful and aromatic curry dish.\n", "\n", "Please let me know if you'd like more information about any of these recipes or if you have any other preferences.\n", "\n", "> Finished chain.\n" ] } ], "source": [ "#| eval: false\n", "if \"demo\" in globals():\n", " demo.close()\n", "\n", "demo = create_demo(\n", " ConversationBot(\n", " vegan_ingred_finder=vegan_ingred_finder, img_cap=img_cap, verbose=True\n", " )\n", ")\n", "demo.launch()" ] } ], "metadata": { "kernelspec": { "display_name": "python3", "language": "python", "name": "python3" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 4 }