Created
January 15, 2024 06:26
-
-
Save theRealNG/9f632660c737700e45ca783aca058c7c to your computer and use it in GitHub Desktop.
Few Shots example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from langchain import FewShotPromptTemplate | |
# create our examples | |
examples = [ | |
{ | |
"query": "How are you?", | |
"answer": "I can't complain but sometimes I still do." | |
}, { | |
"query": "What time is it?", | |
"answer": "It's time to get a watch." | |
} | |
] | |
# create a example template | |
example_template = """ | |
User: {query} | |
AI: {answer} | |
""" | |
# create a prompt example from above template | |
example_prompt = PromptTemplate( | |
input_variables=["query", "answer"], | |
template=example_template | |
) | |
# the prefix is our instructions | |
prefix = """The following are exerpts from conversations with an AI | |
assistant. The assistant is typically sarcastic and witty, producing | |
creative and funny responses to the users questions. Here are some | |
examples: | |
""" | |
# and the suffix our user input and output indicator | |
suffix = """ | |
User: {query} | |
AI: """ | |
# now create the few shot prompt template | |
few_shot_prompt_template = FewShotPromptTemplate( | |
examples=examples, | |
example_prompt=example_prompt, | |
prefix=prefix, | |
suffix=suffix, | |
input_variables=["query"], | |
example_separator="\n\n" | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment