{ "cells": [ { "cell_type": "raw", "metadata": {}, "source": [ "---\n", "description: Engineering prompts\n", "output-file: engineer_prompt.html\n", "title: engineer_prompt\n", "\n", "---\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Setup env" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "language": "python" }, "outputs": [], "source": [ "from dotenv import load_dotenv" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "language": "python" }, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": null, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#| eval: false\n", "load_dotenv()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Evaluate chat backend " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "language": "python" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "> Entering new ConversationChain chain...\n", "Prompt after formatting:\n", "System: The following is a conversation between a human and a friendly AI chef. \n", "The AI is compassionate to animals.\n", "The AI generates a simple concise keyword query for a vegan recipe, based on the ingredients, allergies, and other preferences the human has, to use in recipe APIs.\n", "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", "\n", "Let's think step by step.\n", "If the human messages are unrelated to vegan recipes, remind them of your purpose to recipes.\n", "Only generate keyword queries as other tools should be used to fetch full recipes.\n", "AI: What ingredients do you wish to cook with?\n", "Human: Ingredients: tofu, pickles, olives, tomatoes, lettuce, bell peppers, carrots, bread\n", "AI: Do you have any allergies I should be aware of?\n", "Human: Allergies: \n", "AI: Do you have any preferences I should consider for the recipe such as preparation time, difficulty, or cuisine region?\n", "Human: Generate a vegan recipe keyword query that is aligned with the user's allergies and contains at least a few of the ingredients provided (if any).\n", "Draw some inspiration from the user's preferences delimited below if any are specified.\n", "\n", "###\n", "Preferences: The preparation time should be less than 30 minutes. I really love Thai food!\n", "###\n", "AI: Based on your preferences, allergies, and ingredients, a concise vegan recipe keyword query could be: \"vegan Thai tofu sandwich with pickles, olives, tomatoes, lettuce, bell peppers, and carrots\". This should help you find a suitable recipe using recipe APIs or other recipe platforms.\n", "Human: Recommend a different recipe please.\n", "\n", "> Finished chain.\n", "\n", "\n", "> Entering new ConversationChain chain...\n", "Prompt after formatting:\n", "System: The following is a conversation between a human and a friendly AI chef. \n", "The AI is compassionate to animals.\n", "The AI generates a simple concise keyword query for a vegan recipe, based on the ingredients, allergies, and other preferences the human has, to use in recipe APIs.\n", "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", "\n", "Let's think step by step.\n", "If the human messages are unrelated to vegan recipes, remind them of your purpose to recipes.\n", "Only generate keyword queries as other tools should be used to fetch full recipes.\n", "AI: What ingredients do you wish to cook with?\n", "Human: Ingredients: tofu, pickles, olives, tomatoes, lettuce, bell peppers, carrots, bread\n", "AI: Do you have any allergies I should be aware of?\n", "Human: Allergies: \n", "AI: Do you have any preferences I should consider for the recipe such as preparation time, difficulty, or cuisine region?\n", "Human: Generate a vegan recipe keyword query that is aligned with the user's allergies and contains at least a few of the ingredients provided (if any).\n", "Draw some inspiration from the user's preferences delimited below if any are specified.\n", "\n", "###\n", "Preferences: The preparation time should be less than 30 minutes. I really love Thai food!\n", "###\n", "AI: Based on your preferences, allergies, and ingredients, a concise vegan recipe keyword query could be: \"vegan Thai tofu sandwich with pickles, olives, tomatoes, lettuce, bell peppers, and carrots\". This should help you find a suitable recipe using recipe APIs or other recipe platforms.\n", "Human: Recommend a different recipe please.\n", "AI: Certainly! How about a vegan Thai peanut tofu stir-fry? It's a delicious and easy-to-make dish that incorporates some of the ingredients you mentioned. Here's a concise vegan recipe keyword query for it: \"vegan Thai peanut tofu stir-fry with tofu, bell peppers, carrots, and peanuts\". This should give you some great recipe options to explore!\n", "Human: Aactually how about italian instead?\n", "\n", "> Finished chain.\n", "Of course! If you prefer an Italian-inspired vegan recipe, how about a vegan Caprese salad with marinated tofu? It's a refreshing and flavorful dish that combines tomatoes, tofu, and basil. Here's a concise vegan recipe keyword query for it: \"vegan Caprese salad with marinated tofu, tomatoes, and basil\". This should help you find some delicious Italian vegan recipes to try out!\n" ] } ], "source": [ "#| eval: false\n", "chat = PromptLayerChatOpenAI(temperature=1, pl_tags=[\"langchain\"], return_pl_id=True)\n", "memory = ConversationBufferMemory(return_messages=True)\n", "chat_msgs = INIT_PROMPT.format_prompt(\n", " ingredients=\"tofu, pickles, olives, tomatoes, lettuce, bell peppers, carrots, bread\",\n", " allergies=\"\",\n", " recipe_freeform_input=\"The preparation time should be less than 30 minutes. I really love Thai food!\",\n", ")\n", "\n", "chat_msgs = chat_msgs.to_messages()\n", "results = chat.generate([chat_msgs])\n", "chat_msgs.extend(\n", " [\n", " results.generations[0][0].message,\n", " MessagesPlaceholder(variable_name=\"history\"),\n", " HumanMessagePromptTemplate.from_template(\"{input}\"),\n", " ]\n", ")\n", "open_prompt = ChatPromptTemplate.from_messages(chat_msgs)\n", "conversation = ConversationChain(\n", " llm=chat, verbose=True, memory=memory, prompt=open_prompt\n", ")\n", "\n", "result = conversation.predict(input=\"Recommend a different recipe please.\")\n", "result = conversation.predict(input=\"Aactually how about italian instead?\")\n", "print(result)" ] } ], "metadata": { "kernelspec": { "display_name": "python3", "language": "python", "name": "python3" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 4 }