from dotenv import load_dotenv
engineer_prompt
Engineering prompts
Setup env
load_dotenv()
True
Evaluate chat backend
= PromptLayerChatOpenAI(temperature=1, pl_tags=["langchain"], return_pl_id=True)
chat = ConversationBufferMemory(return_messages=True)
memory = init_prompt.format_prompt(
chat_msgs ="tofu, pickles, olives, tomatoes, lettuce, bell peppers, carrots, bread",
ingredients="",
allergies="The preparation time should be less than 30 minutes. I really love Thai food!",
recipe_freeform_input
)
= chat_msgs.to_messages()
chat_msgs = chat.generate([chat_msgs])
results
chat_msgs.extend(
[0][0].message,
results.generations[="history"),
MessagesPlaceholder(variable_name"{input}"),
HumanMessagePromptTemplate.from_template(
]
)= ChatPromptTemplate.from_messages(chat_msgs)
open_prompt = ConversationChain(
conversation =chat, verbose=True, memory=memory, prompt=open_prompt
llm
)
= conversation.predict(input="Recommend a different recipe please.")
result 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!