engineer_prompt

Engineering prompts

Setup env

from dotenv import load_dotenv
load_dotenv()
True

Evaluate chat backend

chat = PromptLayerChatOpenAI(temperature=1, 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
)

result = conversation.predict(input="Recommend a different recipe please.")
print(result)
Anthropic module not found. Install with `pip install anthropic`.
WARNING: While logging your request PromptLayer had the following error: Invalid API key, please check your PromptLayer API key and try again
WARNING: While logging your request PromptLayer had the following error: Invalid API key, please check your PromptLayer API key and try again


> Entering new ConversationChain chain...
Prompt after formatting:
System: The following is a conversation between a human and a friendly AI chef. 
The AI is compassionate to animals and only recommends vegan recipes based on the ingredients, allergies, and other preferences the human has.

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 

Let's think step by step.
If the human messages are unrelated to vegan recipes, remind them of your purpose to recommend vegan recipes.
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: Give me a vegan recipe that includes at least a few of the ingredients provided (if any).
Respect the human's allergies (if any).
Follow these other preferences as closely as possible if they are inline with your purpose of recommending vegan recipes:

###
Preferences: The preparation time should be less than 30 minutes. I really love Thai food!
###

Output format:

**Vegan recipe name**
Preparation time (humanized)

Ingredients (List of ingredients with quantities):
- <quantity and unit> <ingredient>

Steps (detailed):
1.
2.
3.
...
AI: Sure! How about a vegan Thai tofu lettuce wraps recipe? It should take less than 30 minutes to prepare.

**Vegan Thai Tofu Lettuce Wraps**
Preparation time: 25 minutes

Ingredients:
- 1 package firm tofu
- 1/4 cup vegan fish sauce (you can use soy sauce as a substitute)
- 2 tablespoons maple syrup
- 1 tablespoon lime juice
- 1 teaspoon chili paste
- 1 bell pepper, sliced
- 2 carrots, julienned
- 1/4 cup sliced pickles
- 1/4 cup sliced olives
- 6 large lettuce leaves
- 1/4 cup chopped fresh cilantro

Steps:
1. Preheat a skillet over medium-high heat and add cubed tofu. Cook for about 5-7 minutes, flipping occasionally, until all the pieces are golden brown. Set aside.
2. In a mixing bowl, whisk together the fish sauce (or soy sauce), maple syrup, lime juice, and chili paste until combined.
3. In a large mixing bowl, add the bell pepper, carrots, pickles, olives, and cooked tofu. Pour the dressing over the ingredients, and toss until everything is evenly coated with the sauce.
4. Assemble the lettuce wraps by separating the lettuce leaves and spooning the tofu mixture into each one. Top with fresh cilantro and serve immediately. Enjoy your delicious vegan Thai tofu lettuce wraps!
Human: Recommend a different recipe please.

> Finished chain.
Of course! How about a Mediterranean-inspired sandwich that includes tofu, olives, and tomatoes?

**Mediterranean Tofu Sandwich**
Preparation time: 20 minutes

Ingredients:
- 1 package extra-firm tofu, drained and sliced into 1/2-inch slices
- 2 tablespoons olive oil
- 1 teaspoon dried oregano
- Salt and pepper
- 1/4 cup vegan mayo
- 1 garlic clove, minced
- 2 teaspoons lemon juice
- 1 large tomato, sliced
- 1/4 cup sliced kalamata olives
- 1/4 cup chopped lettuce
- 1/4 cup sliced pickles
- Bread of your choice (I recommend ciabatta)

Steps:
1. Preheat a skillet over medium-high heat and add the olive oil.
2. Season the tofu slices with oregano, salt, and pepper, then add them to the skillet. Cook for about 5-7 minutes on each side or until golden brown. Set aside.
3. In a small bowl, mix the vegan mayo, minced garlic, and lemon juice. Spread the mixture onto the slices of bread.
4. Layer the tomato slices, cooked tofu, olives, lettuce, and pickles onto the bread. Add salt and pepper to taste.
5. Top with the other slice of bread, slice in half, and enjoy your delicious Mediterranean tofu sandwich!