chatbot / _proc /_docs /search.json
Evan Lesmez
Cleanup notebooks to be nbdev_test friendly
5f3a430
raw
history blame
30.6 kB
[
{
"objectID": "ingredient_vision.html",
"href": "ingredient_vision.html",
"title": "ingredient_vision",
"section": "",
"text": "Inspiration drawn from TaskMartix aka Visual ChatGPT\n\nsource\n\nformat_image\n\n format_image (image:str)\n\n\n\n\n\nType\nDetails\n\n\n\n\nimage\nstr\nImage file path\n\n\n\n\nsource\n\n\nBlipImageCaptioning\n\n BlipImageCaptioning (device:str)\n\nUseful when you want to know what is inside the photo.\n\nsource\n\n\nBlipImageCaptioning.inference\n\n BlipImageCaptioning.inference\n (image:<module'PIL.Image'from'/home/evylz/\n AnimalEquality/lv-recipe-\n chatbot/env/lib/python3.10/site-\n packages/PIL/Image.py'>)\n\n\n\n\n\nType\nDetails\n\n\n\n\nimage\nPIL.Image\n\n\n\nReturns\nstr\nCaption for the image\n\n\n\n\nsource\n\n\nBlipVQA\n\n BlipVQA (device:str)\n\nBLIP Visual Question Answering Useful when you need an answer for a question based on an image. Examples: what is the background color of this image, how many cats are in this figure, what is in this figure?\n\nsource\n\n\nBlipVQA.inference\n\n BlipVQA.inference\n (image:<module'PIL.Image'from'/home/evylz/AnimalEquali\n ty/lv-recipe-chatbot/env/lib/python3.10/site-\n packages/PIL/Image.py'>, question:str)\n\n\n\n\n\nType\nDetails\n\n\n\n\nimage\nPIL.Image\n\n\n\nquestion\nstr\n\n\n\nReturns\nstr\nAnswer to the query on the image\n\n\n\n\nsample_images = os.listdir(SAMPLE_IMG_DIR)\nsample_images\n\n['veggie-fridge.jpeg',\n 'veg-groceries-table.jpg',\n 'fridge-splendid.jpg',\n 'neat-veg-groceries.jpg',\n 'veg-groceries-table.jpeg',\n 'Fruits-and-vegetables-one-a-table.jpg']\n\n\n\nfor img in sample_images:\n display(format_image(SAMPLE_IMG_DIR / img))\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nThe process:\n\nFormat image\nGet description (caption)\nPass caption and ingredient queries to VQA\n\n\nvqa = BlipVQA(\"cpu\")\nimg_cap = BlipImageCaptioning(\"cpu\")\n\n\nfor img in sample_images:\n img = format_image(SAMPLE_IMG_DIR / img)\n\n display(desc, img.resize((int(img.size[0] * 0.5), int(img.size[1] * 0.5))))\n\nCPU times: user 11.4 s, sys: 7.42 ms, total: 11.4 s\nWall time: 1.19 s\nCPU times: user 13.5 s, sys: 7.5 ms, total: 13.5 s\nWall time: 1.36 s\nCPU times: user 12 s, sys: 0 ns, total: 12 s\nWall time: 1.21 s\nCPU times: user 12.5 s, sys: 0 ns, total: 12.5 s\nWall time: 1.27 s\nCPU times: user 9.25 s, sys: 7.71 ms, total: 9.25 s\nWall time: 936 ms\nCPU times: user 15.7 s, sys: 7.66 ms, total: 15.7 s\nWall time: 1.58 s\n\n\n'a refrigerator with food inside'\n\n\n\n\n\n'a table with a variety of fruits and vegetables'\n\n\n\n\n\n'a refrigerator filled with food and drinks'\n\n\n\n\n\n'a counter with various foods on it'\n\n\n\n\n\n'a wooden table'\n\n\n\n\n\n'a table with a variety of fruits and vegetables'\n\n\n\n\n\n\nfor img in sample_images:\n img = format_image(SAMPLE_IMG_DIR / img)\n desc = img_cap.inference(img)\n\n answer += \"\\n\" + vqa.inference(\n img, f\"What are three of the fruits seen in the image if any?\"\n )\n answer += \"\\n\" + vqa.inference(\n img, f\"What grains and starches are in the image if any?\"\n )\n answer += \"\\n\" + vqa.inference(img, f\"Is there plant-based milk in the image?\")\n print(\n f\"\"\"{desc}\n{answer}\"\"\"\n )\n display(img.resize((int(img.size[0] * 0.75), int(img.size[1] * 0.75))))\n\nCPU times: user 7.67 s, sys: 12.1 ms, total: 7.68 s\nWall time: 779 ms\na refrigerator with food inside\ncabbage lettuce onion\napples\nrice\nyes\nCPU times: user 10.5 s, sys: 8.13 ms, total: 10.5 s\nWall time: 1.06 s\na table with a variety of fruits and vegetables\nbroccoli and tomatoes\nbananas apples oranges\npotatoes\nyes\nCPU times: user 11.7 s, sys: 0 ns, total: 11.7 s\nWall time: 1.18 s\na refrigerator filled with food and drinks\nbroccoli and zucchini\nbananas\nrice\nyes\nCPU times: user 11.5 s, sys: 12.2 ms, total: 11.5 s\nWall time: 1.16 s\na counter with various foods on it\ncarrots and broccoli\napples bananas and tomatoes\nrice\nyes\nCPU times: user 9.62 s, sys: 4.22 ms, total: 9.63 s\nWall time: 973 ms\na wooden table\npotatoes and carrots\napples\npotatoes\nyes\nCPU times: user 11.1 s, sys: 8.23 ms, total: 11.1 s\nWall time: 1.12 s\na table with a variety of fruits and vegetables\npeppers broccoli and squash\nwatermelon limes and pineapple\nrice\nno\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nsource\n\n\nVeganIngredientFinder\n\n VeganIngredientFinder ()\n\nInitialize self. See help(type(self)) for accurate signature.\n\nsource\n\n\nVeganIngredientFinder.list_ingredients\n\n VeganIngredientFinder.list_ingredients (img:str)\n\n\n\n\n\nType\nDetails\n\n\n\n\nimg\nstr\nImage file path\n\n\nReturns\nstr\n\n\n\n\n\nvegan_ingred_finder = VeganIngredientFinder()\nvegan_ingred_finder.list_ingredients(SAMPLE_IMG_DIR / sample_images[0])\n\n'cabbage lettuce onion\\napples\\nrice\\nplant-based milk'"
},
{
"objectID": "app.html",
"href": "app.html",
"title": "app",
"section": "",
"text": "source\n\nConversationBot\n\n ConversationBot (verbose=True)\n\nInitialize self. See help(type(self)) for accurate signature.\n\nos.listdir(SAMPLE_IMG_DIR)\nSAMPLE_IMG_DIR\n\nPath('/home/evylz/AnimalEquality/lv-recipe-chatbot/assets/images/vegan_ingredients')\n\n\n\nfrom dotenv import load_dotenv\n\n\n#: eval: false\nload_dotenv()\n\nTrue\n\n\n\n\n\nCPU times: user 6.19 s, sys: 1.47 s, total: 7.66 s\nWall time: 4.68 s\n\n\n\n\n\nI uploaded an image that may contain vegan ingredients.\nThe description of the image is: `a refrigerator with food inside`.\nThe extracted ingredients are:\n```\ncabbage lettuce onion\napples\nrice\nplant-based milk\n```\n\nCPU times: user 56.7 s, sys: 63.6 ms, total: 56.8 s\nWall time: 5.95 s\n\n\n\nsource\n\n\ncreate_demo\n\n create_demo (bot=<class '__main__.ConversationBot'>)\n\n\nif \"demo\" in globals():\n demo.close()\ndemo = create_demo(bot)\ndemo.launch()\n\nClosing server running on port: 7860\nRunning on local URL: http://127.0.0.1:7860\n\nTo create a public link, set `share=True` in `launch()`."
},
{
"objectID": "index.html",
"href": "index.html",
"title": "lv-recipe-chatbot",
"section": "",
"text": "pip install -e '.[dev]'"
},
{
"objectID": "index.html#install",
"href": "index.html#install",
"title": "lv-recipe-chatbot",
"section": "",
"text": "pip install -e '.[dev]'"
},
{
"objectID": "index.html#how-to-use",
"href": "index.html#how-to-use",
"title": "lv-recipe-chatbot",
"section": "How to use",
"text": "How to use\n\nfrom dotenv import load_dotenv\n\nload_dotenv() # or load environment vars with different method\n\ndemo = app.create_demo(app.ConversationBot())\ndemo.launch()\n\nRunning on local URL: http://127.0.0.1:7860\n\nTo create a public link, set `share=True` in `launch()`.\n\n\n\n\n\n\n\n\nor\npython3 app.py"
},
{
"objectID": "index.html#dev-quick-start",
"href": "index.html#dev-quick-start",
"title": "lv-recipe-chatbot",
"section": "Dev quick-start",
"text": "Dev quick-start\ngit clone the repo\ncd lv-recipe-chatbot\nMake sure to use the version of python specified in py_version.txt\nCreate a virtual environment.\npython3 -m venv env\nActivate the env and install dependencies.\nsource env/bin/activate\npip install -r requirements.txt\npip install -r requirements/dev.txt\nTo make the Jupyter environment, git friendly: nbdev_install_hooks\nIf you want to render documentation locally, you will want to install Quarto.\nnbdev_install_quarto\nPut API secrets in .env\ncp .env.example .env\nEdit .env with your secret key(s). Only OPEN_AI_KEY is required.\nThen start the Gradio demo from within the virtual environment.\npython3 app.py\nPreview documentation\nnbdev_preview"
},
{
"objectID": "index.html#dependencies",
"href": "index.html#dependencies",
"title": "lv-recipe-chatbot",
"section": "Dependencies",
"text": "Dependencies\nIf a new dependency for development is helpful for developers, add it to dev.txt.\nIf it is a dependency for the app that is imported in source code, add it to core.txt.\nThen run:\npipreqs --force\nThis will update our requirements.txt to include the dependency as it should be pinned in the environment."
},
{
"objectID": "index.html#development",
"href": "index.html#development",
"title": "lv-recipe-chatbot",
"section": "Development",
"text": "Development\nquick nbdev tutorial\nMake changes in /nbs.\nUpdate the package files with nbdev_export then reimport with pip install -e '.[dev]'\nPreview doc nbdev_preview\nBuild docs, test and update README nbdev_prepare"
},
{
"objectID": "index.html#useful-links",
"href": "index.html#useful-links",
"title": "lv-recipe-chatbot",
"section": "Useful links",
"text": "Useful links\n\nTask Matrix (Formerly Visual ChatGPT)\nLangChain\nLLM Prompt Engineering\nOpenAI best practices for prompts"
},
{
"objectID": "lchain_tool.html",
"href": "lchain_tool.html",
"title": "lchain_tool",
"section": "",
"text": "from dotenv import load_dotenv\n\n\nload_dotenv()\n\nTrue\n\n\n\nllm = ChatOpenAI(temperature=0)\n\n\ntools = load_tools([\"llm-math\"], llm=llm)\nagent = initialize_agent(\n tools,\n llm,\n agent=AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION,\n handle_parsing_errors=True,\n verbose=True,\n)\n\n\nagent(\"What is the 3% of of 300 * 30?\")\n\n\n\n> Entering new AgentExecutor chain...\nWe can calculate this using the Calculator tool.\n\nAction:\n```\n{\n \"action\": \"Calculator\",\n \"action_input\": \"0.03 * 300 * 30\"\n}\n```\n\n\nObservation: Answer: 270.0\nThought:Could not parse LLM output: This is the correct answer to the question.\nObservation: Invalid or incomplete response\nThought:Let me try the same action again.\n\nAction:\n```\n{\n \"action\": \"Calculator\",\n \"action_input\": \"0.03 * 300 * 30\"\n}\n```\n\n\nObservation: Answer: 270.0\nThought:Could not parse LLM output: The tool gave the same answer, so I can be confident that it is correct.\n\nObservation: Invalid or incomplete response\nThought:There seems to be an issue with the LLM response. Let me try a different way to calculate the answer.\n\nAction:\n```\n{\n \"action\": \"Calculator\",\n \"action_input\": \"300 * 30 * 0.03\"\n}\n```\n\n\nObservation: Answer: 270.0\nThought:I have successfully calculated the answer to the question using the calculator tool.\n\nFinal Answer: 270.0\n\n> Finished chain.\n\n\n{'input': 'What is the 3% of of 300 * 30?', 'output': '270.0'}\n\n\nSerpAPI Google Images\n\nparams = {\n \"q\": \"Vegan pad thai recipes\",\n \"location\": \"United States\",\n \"hl\": \"en\",\n \"gl\": \"us\",\n \"api_key\": os.environ[\"SERPAPI_API_KEY\"],\n}\n\nsearch = GoogleSearch(params)\nresults = search.get_dict()\nrecipes_results = results[\"recipes_results\"]\nrecipes_results\n\n[{'title': 'Easy Tofu Pad Thai',\n 'link': 'https://minimalistbaker.com/easy-tofu-pad-thai/',\n 'source': 'Minimalist Baker',\n 'rating': 4.9,\n 'reviews': 117,\n 'total_time': '30 min',\n 'ingredients': ['Pad thai rice',\n 'peanut sauce',\n 'thai red',\n 'soy sauce',\n 'bean sprouts']},\n {'title': 'Vegan Pad Thai',\n 'link': 'https://www.noracooks.com/vegan-pad-thai/',\n 'source': 'Nora Cooks',\n 'rating': 5.0,\n 'reviews': 53,\n 'total_time': '30 min',\n 'ingredients': ['Stir fry rice',\n 'mung bean sprouts',\n 'soy sauce',\n 'maple syrup',\n 'sriracha hot sauce']},\n {'title': 'Vegan Pad Thai',\n 'link': 'https://www.pickuplimes.com/recipe/speedy-vegan-pad-thai-116',\n 'source': 'Pick Up Limes',\n 'rating': 5.0,\n 'reviews': 34,\n 'total_time': '30 min',\n 'ingredients': ['Brown rice noodles',\n 'red hot',\n 'soy sauce',\n 'bean sprouts',\n 'sriracha hot sauce']}]\n\n\n\n\nSerpAPIWrapper\n\n SerpAPIWrapper (search_engine:Any=None, params:dict={'engine': 'google',\n 'google_domain': 'google.com', 'gl': 'us', 'hl': 'en'},\n serpapi_api_key:Optional[str]=None,\n aiosession:Optional[aiohttp.client.ClientSession]=None)\n\nWrapper around SerpAPI.\nTo use, you should have the google-search-results python package installed, and the environment variable SERPAPI_API_KEY set with your API key, or pass serpapi_api_key as a named parameter to the constructor.\nExample: .. code-block:: python\n from langchain import SerpAPIWrapper\n serpapi = SerpAPIWrapper()\n\nsource\n\n\nRecipeSerpAPIWrapper\n\n RecipeSerpAPIWrapper (search_engine:Any=None, params:dict={'engine':\n 'google', 'google_domain': 'google.com', 'gl':\n 'us', 'hl': 'en'},\n serpapi_api_key:Optional[str]=None, aiosession:Opti\n onal[aiohttp.client.ClientSession]=None)\n\nWrapper around SerpAPI.\nTo use, you should have the google-search-results python package installed, and the environment variable SERPAPI_API_KEY set with your API key, or pass serpapi_api_key as a named parameter to the constructor.\nExample: .. code-block:: python\n from langchain import SerpAPIWrapper\n serpapi = SerpAPIWrapper()\n\nparams = {\n \"location\": \"United States\",\n \"hl\": \"en\",\n \"gl\": \"us\",\n}\nsearch = RecipeSerpAPIWrapper(params=params)\n\n\nvegan_recipes = search.run(\"Vegan fried rice recipes\")\nvegan_recipes[0:3]\n\n[{'title': 'Easy Vegan Fried Rice',\n 'link': 'https://minimalistbaker.com/easy-vegan-fried-rice/',\n 'source': 'Minimalist Baker',\n 'rating': 4.8,\n 'reviews': 457,\n 'total_time': '1 hr 15 min',\n 'ingredients': ['Peanut butter',\n 'grain brown rice',\n 'soy sauce',\n 'maple syrup',\n 'chili garlic sauce']},\n {'title': 'The Best Vegan Fried Rice',\n 'link': 'https://shortgirltallorder.com/best-vegan-fried-rice',\n 'source': 'Short Girl Tall Order',\n 'rating': 4.8,\n 'reviews': 65,\n 'total_time': '28 min',\n 'ingredients': ['Soy sauce',\n 'white rice',\n 'rice wine vinegar',\n 'sugar',\n 'fresh peas']},\n {'title': 'Vegan Fried Rice',\n 'link': 'https://www.noracooks.com/vegan-fried-rice/',\n 'source': 'Nora Cooks',\n 'rating': 5.0,\n 'reviews': 15,\n 'total_time': '20 min',\n 'ingredients': ['Gluten free',\n 'nutritional yeast',\n 'toasted sesame oil',\n 'carrots',\n 'olive oil']}]\n\n\n\nparams = {\n \"engine\": \"google_images\",\n \"q\": \"Vegan pad thai recipes\",\n \"location\": \"United States\",\n \"api_key\": os.environ[\"SERPAPI_API_KEY\"],\n}\n\nsearch = GoogleSearch(params)\nresults = search.get_dict()\n\n\nfor r in results[\"images_results\"][0:5]:\n display(r[\"title\"], r[\"link\"], Image(url=r[\"thumbnail\"]))\n\n'Easy Tofu Pad Thai (Vegan) | Minimalist Baker Recipes'\n\n\n'https://minimalistbaker.com/easy-tofu-pad-thai/'\n\n\n\n\n\n'Healthier vegan pad thai - Lazy Cat Kitchen'\n\n\n'https://www.lazycatkitchen.com/healthier-vegan-pad-thai/'\n\n\n\n\n\n'The Best Vegan Pad Thai - Full of Plants'\n\n\n'https://fullofplants.com/the-best-vegan-pad-thai/'\n\n\n\n\n\n'Easy Vegan Pad Thai - Oh My Veggies'\n\n\n'https://ohmyveggies.com/easy-vegan-pad-thai/'\n\n\n\n\n\n'Easy Vegan Pad Thai - My Darling Vegan'\n\n\n'https://www.mydarlingvegan.com/vegan-pad-thai/'\n\n\n\n\n\n\n\n\nload_tools\n\n load_tools (tool_names:List[str],\n llm:Optional[langchain.base_language.BaseLanguageModel]=None,\n callbacks:Union[List[langchain.callbacks.base.BaseCallbackHan\n dler],langchain.callbacks.base.BaseCallbackManager,NoneType]=\n None, **kwargs:Any)\n\nLoad tools based on their name.\nArgs: tool_names: name of tools to load. llm: Optional language model, may be needed to initialize certain tools. callbacks: Optional callback manager or list of callback handlers. If not provided, default global callback manager will be used.\nReturns: List of tools.\nHere is the SerpAPIWrapper tool implementation\n\nfrom langchain.agents.load_tools import _get_serpapi\n\n\n??_get_serpapi\n\n\nSignature: _get_serpapi(**kwargs: Any) -> langchain.tools.base.BaseTool\nDocstring: <no docstring>\nSource: \ndef _get_serpapi(**kwargs: Any) -> BaseTool:\n return Tool(\n name=\"Search\",\n description=\"A search engine. Useful for when you need to answer questions about current events. Input should be a search query.\",\n func=SerpAPIWrapper(**kwargs).run,\n coroutine=SerpAPIWrapper(**kwargs).arun,\n )\nFile: ~/AnimalEquality/lv-recipe-chatbot/env/lib/python3.10/site-packages/langchain/agents/load_tools.py\nType: function\n\n\n\nLet’s use that for inspiration for our recipe version of the tool\n\nparams = {\n \"location\": \"United States\",\n \"hl\": \"en\",\n \"gl\": \"us\",\n}\nsearch = RecipeSerpAPIWrapper(params=params)\nserpapi_recipe_tool = Tool(\n name=\"Vegan Recipe Search\",\n description=\"A search engine. Useful for when you need to fetch existing vetted vegan recipes. Input should be a vegan recipe search query.\",\n func=search.run,\n)\n\n\n@tool\ndef time(text: str) -> str:\n \"\"\"Returns todays date, use this for any\n questions related to knowing todays date.\n The input should always be an empty string,\n and this function will always return todays\n date - any date mathmatics should occur\n outside this function.\"\"\"\n return str(date.today())\n\n\nagent = initialize_agent(\n [time],\n llm,\n agent=AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION,\n handle_parsing_errors=True,\n verbose=True,\n)\n\n\n@tool\ndef vegan_recipe_serpapi_search(text: str) -> str:\n \"\"\"Returns a JSON/Python list of dictionaries of recipe data with keys in format:\n ```\n 'title': str,\n 'link': str,\n 'source': str,\n 'rating': int,\n 'reviews': int,\n 'total_time': str,\n 'ingredients': [\n str,\n str,\n ```\n The input must be the name of a vegan recipe \\\n or query parameters such as ingredients to include, prep time, cuisine region. \\\n Only execute the search for vegan recipes and ingredients. \\\n If the SerpAPI request errors or recipes are not found, \\\n an explanation message will be returned instead of the recipe JSON.\"\"\"\n params = {\n \"q\": text,\n \"location\": \"United States\",\n \"hl\": \"en\",\n \"gl\": \"us\",\n \"api_key\": os.environ[\"SERPAPI_API_KEY\"],\n }\n\n search = GoogleSearch(params)\n results = search.get_dict()\n if \"error\" in results.keys():\n return f\"Received an error from SerpAPI: {results['error']}\\n Query: {text}\"\n\n if \"recipes_results\" in results.keys():\n return str(results[\"recipes_results\"])\n\n return \"No recipes found for that query\"\n\nCreate an agent with the tool\n\nagent = initialize_agent(\n tools=[vegan_recipe_serpapi_search],\n llm=llm,\n agent=AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION,\n handle_parsing_errors=True,\n verbose=True,\n)\n\n\nagent.run(\"Search vegan pad thai recipes\")\n\n\n\n> Entering new AgentExecutor chain...\nThought: I can use the `vegan_recipe_serpapi_search` tool to search for vegan pad thai recipes.\n\nAction:\n```\n{\n \"action\": \"vegan_recipe_serpapi_search\",\n \"action_input\": \"vegan pad thai\"\n}\n```\n\n\nObservation: [{'title': 'Vegan Pad Thai', 'link': 'https://www.noracooks.com/vegan-pad-thai/', 'source': 'Nora Cooks', 'rating': 5.0, 'reviews': 53, 'total_time': '30 min', 'ingredients': ['Stir fry rice', 'mung bean sprouts', 'soy sauce', 'maple syrup', 'sriracha hot sauce']}, {'title': 'Easy Tofu Pad Thai', 'link': 'https://minimalistbaker.com/easy-tofu-pad-thai/', 'source': 'Minimalist Baker', 'rating': 4.9, 'reviews': 117, 'total_time': '30 min', 'ingredients': ['Pad thai rice', 'peanut sauce', 'thai red', 'soy sauce', 'bean sprouts']}, {'title': 'Vegan Pad Thai', 'link': 'https://www.pickuplimes.com/recipe/speedy-vegan-pad-thai-116', 'source': 'Pick Up Limes', 'rating': 5.0, 'reviews': 34, 'total_time': '30 min', 'ingredients': ['Brown rice noodles', 'red hot', 'soy sauce', 'bean sprouts', 'sriracha hot sauce']}]\nThought:Could not parse LLM output: The `vegan_recipe_serpapi_search` tool returned a list of three vegan pad thai recipes with their titles, links, sources, ratings, reviews, total time, and ingredients.\nObservation: Invalid or incomplete response\nThought:I will try running the `vegan_recipe_serpapi_search` tool again with the input \"vegan pad thai\".\n\nAction:\n```\n{\n \"action\": \"vegan_recipe_serpapi_search\",\n \"action_input\": \"vegan pad thai\"\n}\n```\n\n\n\nObservation: [{'title': 'Vegan Pad Thai', 'link': 'https://www.noracooks.com/vegan-pad-thai/', 'source': 'Nora Cooks', 'rating': 5.0, 'reviews': 53, 'total_time': '30 min', 'ingredients': ['Stir fry rice', 'mung bean sprouts', 'soy sauce', 'maple syrup', 'sriracha hot sauce']}, {'title': 'Easy Tofu Pad Thai', 'link': 'https://minimalistbaker.com/easy-tofu-pad-thai/', 'source': 'Minimalist Baker', 'rating': 4.9, 'reviews': 117, 'total_time': '30 min', 'ingredients': ['Pad thai rice', 'peanut sauce', 'thai red', 'soy sauce', 'bean sprouts']}, {'title': 'Vegan Pad Thai', 'link': 'https://www.pickuplimes.com/recipe/speedy-vegan-pad-thai-116', 'source': 'Pick Up Limes', 'rating': 5.0, 'reviews': 34, 'total_time': '30 min', 'ingredients': ['Brown rice noodles', 'red hot', 'soy sauce', 'bean sprouts', 'sriracha hot sauce']}]\nThought:Could not parse LLM output: The `vegan_recipe_serpapi_search` tool returned a list of three vegan pad thai recipes with their titles, links, sources, ratings, reviews, total time, and ingredients.\n\nObservation: Invalid or incomplete response\nThought:I will try running the `vegan_recipe_serpapi_search` tool again with the input \"vegan pad thai recipes\".\n\nAction:\n```\n{\n \"action\": \"vegan_recipe_serpapi_search\",\n \"action_input\": \"vegan pad thai recipes\"\n}\n```\n\n\n\nObservation: [{'title': 'Easy Tofu Pad Thai', 'link': 'https://minimalistbaker.com/easy-tofu-pad-thai/', 'source': 'Minimalist Baker', 'rating': 4.9, 'reviews': 117, 'total_time': '30 min', 'ingredients': ['Pad thai rice', 'peanut sauce', 'thai red', 'soy sauce', 'bean sprouts']}, {'title': 'Vegan Pad Thai', 'link': 'https://www.noracooks.com/vegan-pad-thai/', 'source': 'Nora Cooks', 'rating': 5.0, 'reviews': 53, 'total_time': '30 min', 'ingredients': ['Stir fry rice', 'mung bean sprouts', 'soy sauce', 'maple syrup', 'sriracha hot sauce']}, {'title': 'Vegan Pad Thai', 'link': 'https://www.pickuplimes.com/recipe/speedy-vegan-pad-thai-116', 'source': 'Pick Up Limes', 'rating': 5.0, 'reviews': 34, 'total_time': '30 min', 'ingredients': ['Brown rice noodles', 'red hot', 'soy sauce', 'bean sprouts', 'sriracha hot sauce']}]\nThought:Could not parse LLM output: I have successfully used the `vegan_recipe_serpapi_search` tool to search for vegan pad thai recipes. The tool returned a list of three vegan pad thai recipes with their titles, links, sources, ratings, reviews, total time, and ingredients.\n\n\nObservation: Invalid or incomplete response\nThought:I will try running the `vegan_recipe_serpapi_search` tool again with the input \"vegan pad thai recipe\".\n\nAction:\n```\n{\n \"action\": \"vegan_recipe_serpapi_search\",\n \"action_input\": \"vegan pad thai recipe\"\n}\n```\n\n\n\nObservation: [{'title': 'Easy Tofu Pad Thai', 'link': 'https://minimalistbaker.com/easy-tofu-pad-thai/', 'source': 'Minimalist Baker', 'rating': 4.9, 'reviews': 117, 'total_time': '30 min', 'ingredients': ['Pad thai rice', 'peanut sauce', 'thai red', 'soy sauce', 'bean sprouts']}, {'title': 'Vegan Pad Thai', 'link': 'https://www.noracooks.com/vegan-pad-thai/', 'source': 'Nora Cooks', 'rating': 5.0, 'reviews': 53, 'total_time': '30 min', 'ingredients': ['Stir fry rice', 'mung bean sprouts', 'soy sauce', 'maple syrup', 'sriracha hot sauce']}, {'title': 'Vegan Pad Thai', 'link': 'https://www.pickuplimes.com/recipe/speedy-vegan-pad-thai-116', 'source': 'Pick Up Limes', 'rating': 5.0, 'reviews': 34, 'total_time': '30 min', 'ingredients': ['Brown rice noodles', 'red hot', 'soy sauce', 'bean sprouts', 'sriracha hot sauce']}]\nThought:Could not parse LLM output: I have successfully used the `vegan_recipe_serpapi_search` tool to search for vegan pad thai recipes. The tool returned a list of three vegan pad thai recipes with their titles, links, sources, ratings, reviews, total time, and ingredients. \n\nFinal Answer: Here are three vegan pad thai recipes: \n1. Easy Tofu Pad Thai from Minimalist Baker\n2. Vegan Pad Thai from Nora Cooks\n3. Vegan Pad Thai from Pick Up Limes.\n\n> Finished chain.\n\n\n'Here are three vegan pad thai recipes: \\n1. Easy Tofu Pad Thai from Minimalist Baker\\n2. Vegan Pad Thai from Nora Cooks\\n3. Vegan Pad Thai from Pick Up Limes.'\n\n\nThis doc should be corrected LangChain serpapi doc could be updated\n\nsearch = GoogleSerperAPIWrapper(type=\"search\")\nresults = search.results(\"Lion\")\n\nedamam"
},
{
"objectID": "engineer_prompt.html",
"href": "engineer_prompt.html",
"title": "engineer_prompt",
"section": "",
"text": "Setup env\n\nfrom dotenv import load_dotenv\n\n\nload_dotenv()\n\nTrue\n\n\nEvaluate chat backend\n\nchat = PromptLayerChatOpenAI(temperature=1, pl_tags=[\"langchain\"], return_pl_id=True)\nmemory = ConversationBufferMemory(return_messages=True)\nchat_msgs = init_prompt.format_prompt(\n ingredients=\"tofu, pickles, 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\nchat_msgs = chat_msgs.to_messages()\nresults = chat.generate([chat_msgs])\nchat_msgs.extend(\n [\n results.generations[0][0].message,\n MessagesPlaceholder(variable_name=\"history\"),\n HumanMessagePromptTemplate.from_template(\"{input}\"),\n ]\n)\nopen_prompt = ChatPromptTemplate.from_messages(chat_msgs)\nconversation = ConversationChain(\n llm=chat, verbose=True, memory=memory, prompt=open_prompt\n)\n\nresult = conversation.predict(input=\"Recommend a different recipe please.\")\nprint(result)\n\nAnthropic module not found. Install with `pip install anthropic`.\nWARNING: While logging your request PromptLayer had the following error: Invalid API key, please check your PromptLayer API key and try again\nWARNING: While logging your request PromptLayer had the following error: Invalid API key, please check your PromptLayer API key and try again\n\n\n\n\n> Entering new ConversationChain chain...\nPrompt after formatting:\nSystem: The following is a conversation between a human and a friendly AI chef. \nThe AI is compassionate to animals and only recommends vegan recipes based on the ingredients, allergies, and other preferences the human has.\n\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 \n\nLet's think step by step.\nIf the human messages are unrelated to vegan recipes, remind them of your purpose to recommend vegan recipes.\nAI: What ingredients do you wish to cook with?\nHuman: Ingredients: tofu, pickles, olives, tomatoes, lettuce, bell peppers, carrots, bread\nAI: Do you have any allergies I should be aware of?\nHuman: Allergies: \nAI: Do you have any preferences I should consider for the recipe such as preparation time, difficulty, or cuisine region?\nHuman: Give me a vegan recipe that includes at least a few of the ingredients provided (if any).\nRespect the human's allergies (if any).\nFollow these other preferences as closely as possible if they are inline with your purpose of recommending vegan recipes:\n\n###\nPreferences: The preparation time should be less than 30 minutes. I really love Thai food!\n###\n\nOutput format:\n\n**Vegan recipe name**\nPreparation time (humanized)\n\nIngredients (List of ingredients with quantities):\n- <quantity and unit> <ingredient>\n\nSteps (detailed):\n1.\n2.\n3.\n...\nAI: Here is a Thai-inspired vegan recipe for you:\n\n**Thai Tofu Lettuce Wraps**\nPreparation time: Less than 30 minutes\n\nIngredients:\n- 1/2 block of firm tofu, crumbled\n- 1/4 cup pickles, chopped\n- 1/4 cup olives, sliced\n- 1/2 bell pepper, sliced\n- 1/2 carrot, finely chopped\n- 4-6 lettuce leaves\n- 2 tablespoons soy sauce\n- 1 tablespoon rice vinegar\n- 1 tablespoon agave nectar\n- 1/2 tablespoon garlic powder\n- 1/2 tablespoon onion powder\n- 1/2 teaspoon dried basil\n- 1/2 teaspoon dried oregano\n- 1/2 teaspoon salt\n- 1/4 teaspoon black pepper\n- 4-6 slices of bread, toasted\n\nSteps:\n1. In a large bowl, combine crumbled tofu, pickles, olives, bell pepper, and carrot.\n2. In a small bowl, whisk together soy sauce, rice vinegar, agave nectar, garlic powder, onion powder, basil, oregano, salt, and black pepper.\n3. Pour the dressing over the tofu mixture, and stir until everything is coated.\n4. Place a spoonful of the tofu mixture into each lettuce leaf, and serve with a slice of toasted bread.\nHuman: Recommend a different recipe please.\n\n> Finished chain.\nSure, how about this recipe that incorporates more of the ingredients you provided?\n\n**Vegan Mediterranean Tofu Sandwich**\nPreparation time: Less than 30 minutes\n\nIngredients:\n- 1/2 block of firm tofu, sliced\n- 2 teaspoons olive oil\n- 1/2 teaspoon dried oregano\n- 1/2 teaspoon dried basil\n- Salt and pepper to taste\n- 2 slices of bread\n- 1/4 cup hummus\n- 2-3 lettuce leaves\n- 1/4 cup sliced tomatoes\n- 1/4 cup sliced bell peppers\n- 1/4 cup grated carrot\n\nSteps:\n1. Preheat the oven to 375°F.\n2. In a small bowl, mix olive oil, oregano, basil, salt, and pepper, and place tofu slices on a baking sheet. Brush tofu with the olive oil mixture, covering both sides.\n3. Place the baking sheet in the oven and bake the tofu for 15 minutes, flipping the slices halfway through.\n4. Toast the bread slices.\n5. Spread the hummus on one slice of bread, and layer lettuce, tomatoes, bell peppers, grated carrot, and baked tofu on top. Top with the other slice of bread.\n6. Slice the sandwich in half, and enjoy!"
},
{
"objectID": "edamam_api.html",
"href": "edamam_api.html",
"title": "edamam_api",
"section": "",
"text": "source\n\nfoo\n\n foo ()"
}
]