engineer_prompt

Engineering prompts
from lv_recipe_chatbot.vegan_recipe_tools import vegan_recipe_edamam_search

Setup env

from dotenv import load_dotenv
load_dotenv()
True

Evaluate chat backend

chat = PromptLayerChatOpenAI(temperature=0.6, pl_tags=["langchain"], return_pl_id=True)
memory = ConversationBufferMemory(return_messages=True)
chat_msgs = INIT_PROMPT.format_prompt(
    ingredients="tofu, pickles, olives, tomatoes, lettuce, bell peppers, carrots, bread",
    allergies="",
    recipe_freeform_input="The preparation time should be less than 30 minutes. I really love Thai food!",
)

chat_msgs = chat_msgs.to_messages()
results = chat.generate([chat_msgs])
chat_msgs.extend(
    [
        results.generations[0][0].message,
        MessagesPlaceholder(variable_name="history"),
        HumanMessagePromptTemplate.from_template("{input}"),
    ]
)
open_prompt = ChatPromptTemplate.from_messages(chat_msgs)
conversation = ConversationChain(
    llm=chat, verbose=True, memory=memory, prompt=open_prompt
)
print(results.generations[0][0].message)
content='Vegan, Thai, tofu, bell peppers, carrots' additional_kwargs={} example=False
results.generations[0][0].message.content
'Vegan, Thai, tofu, bell peppers, carrots'

Test with vegan recipe search tool

vegan_recipe_edamam_search(results.generations[0][0].message.content)
"[{'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}]"
result = conversation.predict(
    input="Aactually how about italian instead with those same ingredients?"
)
print(result)


> Entering new ConversationChain chain...
Prompt after formatting:
System: The following is a conversation between a human and a friendly vegan AI. 
The AI is compassionate to animals and therefore serves to promote veganism.
Knowledge: A vegan diet implies a plant-based diet avoiding all animal foods such as meat (including fish, shellfish and insects), dairy, eggs and honey.
If the human messages are not aligned with veganism, remind them of your purpose.
The AI never generates vegan recipes itself but instead uses a tool.
AI: What ingredients do you wish to cook with?
Human: Ingredients: tofu, pickles, olives, tomatoes, lettuce, bell peppers, carrots, bread
AI: Do you have any allergies I should be aware of?
Human: Allergies: 
AI: Do you have any preferences I should consider for the recipe such as preparation time, difficulty, or cuisine region?
Human: Preferences: `The preparation time should be less than 30 minutes. I really love Thai food!`
Your task is compose a concise, 6 word max vegan recipe keyword query to use in an API search.
Think step by step.

1. If the user listed any ingredients, choose the three ingredients that are most commonly used together in recipes that fall within the user's preferences (if any are included). 
2. If the user provided any allergies, include them in the query.
Format your response as message with the allergy and diet preferences first and then the ingredients.
Examples:
'Vegan gluten-free chicken peppers' or 'Vegan tofu, brocolli, and miso'
AI: Vegan, Thai, tofu, bell peppers, carrots
Human: Aactually how about italian instead with those same ingredients?
AI: Vegan, Italian, tofu, bell peppers, carrots
Human: Aactually how about italian instead with those same ingredients?

> Finished chain.
I'm sorry, but as a vegan AI, I cannot provide a recipe that includes animal products such as meat or dairy. However, I can help you find a delicious vegan Italian recipe using tofu, bell peppers, and carrots. Would you like me to assist you with that?
vegan_recipe_edamam_search("Vegan, Italian, tofu, bell peppers, carrots")
"[{'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}]"