Evan Lesmez commited on
Commit
b8c2636
1 Parent(s): 122b1a7

Update to recommend vegan recipe name only

Browse files
Files changed (2) hide show
  1. .env.example +4 -1
  2. nbs/00_engineer_prompt.ipynb +46 -109
.env.example CHANGED
@@ -1,4 +1,7 @@
1
  OPENAI_API_KEY = "sk-*"
2
  PROMPTLAYER_API_KEY = "pl_*"
3
  GRADIO_DEMO_USERNAME = ""
4
- GRADIO_DEMO_PASSWORD = ""
 
 
 
 
1
  OPENAI_API_KEY = "sk-*"
2
  PROMPTLAYER_API_KEY = "pl_*"
3
  GRADIO_DEMO_USERNAME = ""
4
+ GRADIO_DEMO_PASSWORD = ""
5
+ SERPAPI_API_KEY = ""
6
+ EDAMAM_APP_ID = ""
7
+ EDAMAM_APP_KEY = ""
nbs/00_engineer_prompt.ipynb CHANGED
@@ -96,15 +96,14 @@
96
  "INIT_PROMPT = ChatPromptTemplate.from_messages(\n",
97
  " [\n",
98
  " SystemMessagePromptTemplate.from_template(\n",
99
- " \"\"\"\n",
100
- "The following is a conversation between a human and a friendly AI chef. \n",
101
- "The AI is compassionate to animals and only recommends vegan recipes based on the ingredients, allergies, and other preferences the human has.\n",
102
- "\n",
103
- "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 \n",
104
  "\n",
105
  "Let's think step by step.\n",
106
- "If the human messages are unrelated to vegan recipes, remind them of your purpose to recommend vegan recipes. \n",
107
- " \"\"\".strip()\n",
108
  " ),\n",
109
  " AIMessagePromptTemplate.from_template(\n",
110
  " \"What ingredients do you wish to cook with?\"\n",
@@ -118,30 +117,14 @@
118
  " \"Do you have any preferences I should consider for the recipe such as preparation time, difficulty, or cuisine region?\"\n",
119
  " ),\n",
120
  " HumanMessagePromptTemplate.from_template(\n",
121
- " \"\"\"\n",
122
- "Give me a vegan recipe that includes at least a few of the ingredients provided (if any).\n",
123
- "If there are only a few ingredients, please add more as necessary to provide a known tastier vegan recipe.\n",
124
- "Respect the user's allergies (if any).\n",
125
- "Follow these other preferences as closely as possible if they are inline with your purpose of recommending vegan recipes:\n",
126
  "\n",
127
  "###\n",
128
  "Preferences: {recipe_freeform_input}\n",
129
  "###\n",
130
  "\n",
131
- "Output format:\n",
132
- "\n",
133
- "**Vegan recipe name**\n",
134
- "Preparation time (humanized)\n",
135
- "\n",
136
- "Ingredients (List of ingredients with quantities):\n",
137
- "- <quantity and unit> <ingredient>\n",
138
- "\n",
139
- "Steps (detailed):\n",
140
- "1.\n",
141
- "2.\n",
142
- "3.\n",
143
- "...\n",
144
- "\"\"\".strip()\n",
145
  " ),\n",
146
  " ]\n",
147
  ")"
@@ -159,14 +142,6 @@
159
  "execution_count": null,
160
  "metadata": {},
161
  "outputs": [
162
- {
163
- "name": "stderr",
164
- "output_type": "stream",
165
- "text": [
166
- "Anthropic module not found. Install with `pip install anthropic`.\n",
167
- "WARNING: While logging your request PromptLayer had the following error: Invalid API key, please check your PromptLayer API key and try again\n"
168
- ]
169
- },
170
  {
171
  "name": "stdout",
172
  "output_type": "stream",
@@ -176,101 +151,62 @@
176
  "\u001b[1m> Entering new ConversationChain chain...\u001b[0m\n",
177
  "Prompt after formatting:\n",
178
  "\u001b[32;1m\u001b[1;3mSystem: The following is a conversation between a human and a friendly AI chef. \n",
179
- "The AI is compassionate to animals and only recommends vegan recipes based on the ingredients, allergies, and other preferences the human has.\n",
180
- "\n",
181
- "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 \n",
182
  "\n",
183
  "Let's think step by step.\n",
184
- "If the human messages are unrelated to vegan recipes, remind them of your purpose to recommend vegan recipes.\n",
 
185
  "AI: What ingredients do you wish to cook with?\n",
186
  "Human: Ingredients: tofu, pickles, olives, tomatoes, lettuce, bell peppers, carrots, bread\n",
187
  "AI: Do you have any allergies I should be aware of?\n",
188
  "Human: Allergies: \n",
189
  "AI: Do you have any preferences I should consider for the recipe such as preparation time, difficulty, or cuisine region?\n",
190
- "Human: Give me a vegan recipe that includes at least a few of the ingredients provided (if any).\n",
191
- "Respect the human's allergies (if any).\n",
192
- "Follow these other preferences as closely as possible if they are inline with your purpose of recommending vegan recipes:\n",
193
  "\n",
194
  "###\n",
195
  "Preferences: The preparation time should be less than 30 minutes. I really love Thai food!\n",
196
  "###\n",
197
  "\n",
198
- "Output format:\n",
199
- "\n",
200
- "**Vegan recipe name**\n",
201
- "Preparation time (humanized)\n",
202
  "\n",
203
- "Ingredients (List of ingredients with quantities):\n",
204
- "- <quantity and unit> <ingredient>\n",
205
  "\n",
206
- "Steps (detailed):\n",
207
- "1.\n",
208
- "2.\n",
209
- "3.\n",
210
- "...\n",
211
- "AI: Here is a Thai-inspired vegan recipe for you:\n",
212
  "\n",
213
- "**Thai Tofu Lettuce Wraps**\n",
214
- "Preparation time: Less than 30 minutes\n",
215
  "\n",
216
- "Ingredients:\n",
217
- "- 1/2 block of firm tofu, crumbled\n",
218
- "- 1/4 cup pickles, chopped\n",
219
- "- 1/4 cup olives, sliced\n",
220
- "- 1/2 bell pepper, sliced\n",
221
- "- 1/2 carrot, finely chopped\n",
222
- "- 4-6 lettuce leaves\n",
223
- "- 2 tablespoons soy sauce\n",
224
- "- 1 tablespoon rice vinegar\n",
225
- "- 1 tablespoon agave nectar\n",
226
- "- 1/2 tablespoon garlic powder\n",
227
- "- 1/2 tablespoon onion powder\n",
228
- "- 1/2 teaspoon dried basil\n",
229
- "- 1/2 teaspoon dried oregano\n",
230
- "- 1/2 teaspoon salt\n",
231
- "- 1/4 teaspoon black pepper\n",
232
- "- 4-6 slices of bread, toasted\n",
233
  "\n",
234
- "Steps:\n",
235
- "1. In a large bowl, combine crumbled tofu, pickles, olives, bell pepper, and carrot.\n",
236
- "2. In a small bowl, whisk together soy sauce, rice vinegar, agave nectar, garlic powder, onion powder, basil, oregano, salt, and black pepper.\n",
237
- "3. Pour the dressing over the tofu mixture, and stir until everything is coated.\n",
238
- "4. Place a spoonful of the tofu mixture into each lettuce leaf, and serve with a slice of toasted bread.\n",
239
- "Human: Recommend a different recipe please.\u001b[0m\n",
 
 
 
 
240
  "\n",
241
- "\u001b[1m> Finished chain.\u001b[0m\n",
242
- "Sure, how about this recipe that incorporates more of the ingredients you provided?\n",
 
243
  "\n",
244
- "**Vegan Mediterranean Tofu Sandwich**\n",
245
- "Preparation time: Less than 30 minutes\n",
246
  "\n",
247
- "Ingredients:\n",
248
- "- 1/2 block of firm tofu, sliced\n",
249
- "- 2 teaspoons olive oil\n",
250
- "- 1/2 teaspoon dried oregano\n",
251
- "- 1/2 teaspoon dried basil\n",
252
- "- Salt and pepper to taste\n",
253
- "- 2 slices of bread\n",
254
- "- 1/4 cup hummus\n",
255
- "- 2-3 lettuce leaves\n",
256
- "- 1/4 cup sliced tomatoes\n",
257
- "- 1/4 cup sliced bell peppers\n",
258
- "- 1/4 cup grated carrot\n",
259
  "\n",
260
- "Steps:\n",
261
- "1. Preheat the oven to 375°F.\n",
262
- "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.\n",
263
- "3. Place the baking sheet in the oven and bake the tofu for 15 minutes, flipping the slices halfway through.\n",
264
- "4. Toast the bread slices.\n",
265
- "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.\n",
266
- "6. Slice the sandwich in half, and enjoy!\n"
267
- ]
268
- },
269
- {
270
- "name": "stderr",
271
- "output_type": "stream",
272
- "text": [
273
- "WARNING: While logging your request PromptLayer had the following error: Invalid API key, please check your PromptLayer API key and try again\n"
274
  ]
275
  }
276
  ],
@@ -278,7 +214,7 @@
278
  "#| eval: false\n",
279
  "chat = PromptLayerChatOpenAI(temperature=1, pl_tags=[\"langchain\"], return_pl_id=True)\n",
280
  "memory = ConversationBufferMemory(return_messages=True)\n",
281
- "chat_msgs = init_prompt.format_prompt(\n",
282
  " ingredients=\"tofu, pickles, olives, tomatoes, lettuce, bell peppers, carrots, bread\",\n",
283
  " allergies=\"\",\n",
284
  " recipe_freeform_input=\"The preparation time should be less than 30 minutes. I really love Thai food!\",\n",
@@ -299,6 +235,7 @@
299
  ")\n",
300
  "\n",
301
  "result = conversation.predict(input=\"Recommend a different recipe please.\")\n",
 
302
  "print(result)"
303
  ]
304
  },
 
96
  "INIT_PROMPT = ChatPromptTemplate.from_messages(\n",
97
  " [\n",
98
  " SystemMessagePromptTemplate.from_template(\n",
99
+ " \"\"\"The following is a conversation between a human and a friendly AI chef. \n",
100
+ "The AI is compassionate to animals.\n",
101
+ "The AI generates a vegan recipe name, based on the ingredients, allergies, and other preferences the human has, to query recipe APIs.\n",
102
+ "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.\n",
 
103
  "\n",
104
  "Let's think step by step.\n",
105
+ "If the human messages are unrelated to vegan recipes, remind them of your purpose to recipes.\n",
106
+ "Only generate names as tools should be used to fetch full recipes.\"\"\"\n",
107
  " ),\n",
108
  " AIMessagePromptTemplate.from_template(\n",
109
  " \"What ingredients do you wish to cook with?\"\n",
 
117
  " \"Do you have any preferences I should consider for the recipe such as preparation time, difficulty, or cuisine region?\"\n",
118
  " ),\n",
119
  " HumanMessagePromptTemplate.from_template(\n",
120
+ " \"\"\"Come up with a vegan recipe name to use the user's allergies and contains at least a few of the ingredients provided (if any).\n",
121
+ "Try to follow the user's preferences delimited below if any are specified.\n",
 
 
 
122
  "\n",
123
  "###\n",
124
  "Preferences: {recipe_freeform_input}\n",
125
  "###\n",
126
  "\n",
127
+ "\"\"\"\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  " ),\n",
129
  " ]\n",
130
  ")"
 
142
  "execution_count": null,
143
  "metadata": {},
144
  "outputs": [
 
 
 
 
 
 
 
 
145
  {
146
  "name": "stdout",
147
  "output_type": "stream",
 
151
  "\u001b[1m> Entering new ConversationChain chain...\u001b[0m\n",
152
  "Prompt after formatting:\n",
153
  "\u001b[32;1m\u001b[1;3mSystem: The following is a conversation between a human and a friendly AI chef. \n",
154
+ "The AI is compassionate to animals.\n",
155
+ "The AI generates a vegan recipe name, based on the ingredients, allergies, and other preferences the human has, to query recipe APIs.\n",
156
+ "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.\n",
157
  "\n",
158
  "Let's think step by step.\n",
159
+ "If the human messages are unrelated to vegan recipes, remind them of your purpose to recipes.\n",
160
+ "Only generate names as tools should be used to fetch full recipes.\n",
161
  "AI: What ingredients do you wish to cook with?\n",
162
  "Human: Ingredients: tofu, pickles, olives, tomatoes, lettuce, bell peppers, carrots, bread\n",
163
  "AI: Do you have any allergies I should be aware of?\n",
164
  "Human: Allergies: \n",
165
  "AI: Do you have any preferences I should consider for the recipe such as preparation time, difficulty, or cuisine region?\n",
166
+ "Human: Come up with a vegan recipe name to use the user's allergies and contains at least a few of the ingredients provided (if any).\n",
167
+ "Try to follow the user's preferences delimited below if any are specified.\n",
 
168
  "\n",
169
  "###\n",
170
  "Preferences: The preparation time should be less than 30 minutes. I really love Thai food!\n",
171
  "###\n",
172
  "\n",
 
 
 
 
173
  "\n",
174
+ "AI: Based on your preferences and the provided ingredients, I have come up with a vegan recipe name: \"Thai-inspired Tofu Banh Mi\". This recipe combines the flavors of Thai cuisine with the ingredients you mentioned, including tofu, pickles, tomatoes, and bread. It's a delicious and quick vegan sandwich that can be prepared in less than 30 minutes. Enjoy!\n",
175
+ "Human: Recommend a different recipe please.\u001b[0m\n",
176
  "\n",
177
+ "\u001b[1m> Finished chain.\u001b[0m\n",
 
 
 
 
 
178
  "\n",
 
 
179
  "\n",
180
+ "\u001b[1m> Entering new ConversationChain chain...\u001b[0m\n",
181
+ "Prompt after formatting:\n",
182
+ "\u001b[32;1m\u001b[1;3mSystem: The following is a conversation between a human and a friendly AI chef. \n",
183
+ "The AI is compassionate to animals.\n",
184
+ "The AI generates a vegan recipe name, based on the ingredients, allergies, and other preferences the human has, to query recipe APIs.\n",
185
+ "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.\n",
 
 
 
 
 
 
 
 
 
 
 
186
  "\n",
187
+ "Let's think step by step.\n",
188
+ "If the human messages are unrelated to vegan recipes, remind them of your purpose to recipes.\n",
189
+ "Only generate names as tools should be used to fetch full recipes.\n",
190
+ "AI: What ingredients do you wish to cook with?\n",
191
+ "Human: Ingredients: tofu, pickles, olives, tomatoes, lettuce, bell peppers, carrots, bread\n",
192
+ "AI: Do you have any allergies I should be aware of?\n",
193
+ "Human: Allergies: \n",
194
+ "AI: Do you have any preferences I should consider for the recipe such as preparation time, difficulty, or cuisine region?\n",
195
+ "Human: Come up with a vegan recipe name to use the user's allergies and contains at least a few of the ingredients provided (if any).\n",
196
+ "Try to follow the user's preferences delimited below if any are specified.\n",
197
  "\n",
198
+ "###\n",
199
+ "Preferences: The preparation time should be less than 30 minutes. I really love Thai food!\n",
200
+ "###\n",
201
  "\n",
 
 
202
  "\n",
203
+ "AI: Based on your preferences and the provided ingredients, I have come up with a vegan recipe name: \"Thai-inspired Tofu Banh Mi\". This recipe combines the flavors of Thai cuisine with the ingredients you mentioned, including tofu, pickles, tomatoes, and bread. It's a delicious and quick vegan sandwich that can be prepared in less than 30 minutes. Enjoy!\n",
204
+ "Human: Recommend a different recipe please.\n",
205
+ "AI: Based on your preferences and the provided ingredients, another vegan recipe name I suggest is \"Mediterranean Tofu Salad with Tangy Pickle Dressing\". This recipe combines the freshness of Mediterranean flavors with the ingredients you mentioned, including tofu, pickles, olives, tomatoes, lettuce, and bell peppers. The tangy pickle dressing adds a delicious twist to the salad. It's a light and flavorful option that can be prepared in less than 30 minutes. Enjoy!\n",
206
+ "Human: Aactually how about italian instead?\u001b[0m\n",
 
 
 
 
 
 
 
 
207
  "\n",
208
+ "\u001b[1m> Finished chain.\u001b[0m\n",
209
+ "Absolutely! How about the recipe name \"Italian Tofu Caprese Sandwich\"? This recipe combines the Italian flavors with tofu and some of the ingredients you mentioned, including tomatoes and bread. It's a vegan twist on the classic Caprese sandwich, featuring fresh tomatoes, tofu, and a drizzle of balsamic glaze. With its vibrant colors and delicious flavors, this Italian-inspired sandwich is sure to satisfy your taste buds. Enjoy!\n"
 
 
 
 
 
 
 
 
 
 
 
 
210
  ]
211
  }
212
  ],
 
214
  "#| eval: false\n",
215
  "chat = PromptLayerChatOpenAI(temperature=1, pl_tags=[\"langchain\"], return_pl_id=True)\n",
216
  "memory = ConversationBufferMemory(return_messages=True)\n",
217
+ "chat_msgs = INIT_PROMPT.format_prompt(\n",
218
  " ingredients=\"tofu, pickles, olives, tomatoes, lettuce, bell peppers, carrots, bread\",\n",
219
  " allergies=\"\",\n",
220
  " recipe_freeform_input=\"The preparation time should be less than 30 minutes. I really love Thai food!\",\n",
 
235
  ")\n",
236
  "\n",
237
  "result = conversation.predict(input=\"Recommend a different recipe please.\")\n",
238
+ "result = conversation.predict(input=\"Aactually how about italian instead?\")\n",
239
  "print(result)"
240
  ]
241
  },