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: Here is a Thai-inspired vegan recipe for you:

**Thai Tofu Lettuce Wraps**
Preparation time: Less than 30 minutes

Ingredients:
- 1/2 block of firm tofu, crumbled
- 1/4 cup pickles, chopped
- 1/4 cup olives, sliced
- 1/2 bell pepper, sliced
- 1/2 carrot, finely chopped
- 4-6 lettuce leaves
- 2 tablespoons soy sauce
- 1 tablespoon rice vinegar
- 1 tablespoon agave nectar
- 1/2 tablespoon garlic powder
- 1/2 tablespoon onion powder
- 1/2 teaspoon dried basil
- 1/2 teaspoon dried oregano
- 1/2 teaspoon salt
- 1/4 teaspoon black pepper
- 4-6 slices of bread, toasted

Steps:
1. In a large bowl, combine crumbled tofu, pickles, olives, bell pepper, and carrot.
2. In a small bowl, whisk together soy sauce, rice vinegar, agave nectar, garlic powder, onion powder, basil, oregano, salt, and black pepper.
3. Pour the dressing over the tofu mixture, and stir until everything is coated.
4. Place a spoonful of the tofu mixture into each lettuce leaf, and serve with a slice of toasted bread.
Human: Recommend a different recipe please.

> Finished chain.
Sure, how about this recipe that incorporates more of the ingredients you provided?

**Vegan Mediterranean Tofu Sandwich**
Preparation time: Less than 30 minutes

Ingredients:
- 1/2 block of firm tofu, sliced
- 2 teaspoons olive oil
- 1/2 teaspoon dried oregano
- 1/2 teaspoon dried basil
- Salt and pepper to taste
- 2 slices of bread
- 1/4 cup hummus
- 2-3 lettuce leaves
- 1/4 cup sliced tomatoes
- 1/4 cup sliced bell peppers
- 1/4 cup grated carrot

Steps:
1. Preheat the oven to 375°F.
2. 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.
3. Place the baking sheet in the oven and bake the tofu for 15 minutes, flipping the slices halfway through.
4. Toast the bread slices.
5. 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.
6. Slice the sandwich in half, and enjoy!