File size: 2,331 Bytes
adaea7c
 
 
986fa13
adaea7c
 
5f3a430
4edc753
adaea7c
4edc753
 
adaea7c
4edc753
 
 
adaea7c
4edc753
adaea7c
4edc753
adaea7c
986fa13
4edc753
 
63ae673
 
 
 
4edc753
 
63ae673
 
4edc753
 
 
 
 
 
 
 
 
 
29fa9df
4edc753
 
63ae673
 
4edc753
 
29fa9df
63ae673
4edc753
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_engineer_prompt.ipynb.

# %% auto 0
__all__ = ['INIT_PROMPT']

# %% ../nbs/00_engineer_prompt.ipynb 3
import openai
from langchain.chains import ConversationChain
from langchain.chat_models import PromptLayerChatOpenAI
from langchain.memory import ConversationBufferMemory
from langchain.prompts.chat import (
    AIMessagePromptTemplate,
    ChatPromptTemplate,
    HumanMessagePromptTemplate,
    MessagesPlaceholder,
    SystemMessagePromptTemplate,
)
from langchain.schema import AIMessage, HumanMessage, SystemMessage

# %% ../nbs/00_engineer_prompt.ipynb 7
INIT_PROMPT = ChatPromptTemplate.from_messages(
    [
        SystemMessagePromptTemplate.from_template(
            """The following is a conversation between a human and a friendly AI chef. 
The AI is compassionate to animals.
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.
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 recipes.
Only generate keyword queries as other tools should be used to fetch full recipes."""
        ),
        AIMessagePromptTemplate.from_template(
            "What ingredients do you wish to cook with?"
        ),
        HumanMessagePromptTemplate.from_template("Ingredients: {ingredients}"),
        AIMessagePromptTemplate.from_template(
            "Do you have any allergies I should be aware of?"
        ),
        HumanMessagePromptTemplate.from_template("Allergies: {allergies}"),
        AIMessagePromptTemplate.from_template(
            "Do you have any preferences I should consider for the recipe such as preparation time, difficulty, or cuisine region?"
        ),
        HumanMessagePromptTemplate.from_template(
            """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).
Draw some inspiration from the user's preferences delimited below if any are specified.

###
Preferences: {recipe_freeform_input}
###"""
        ),
    ]
)