"horse"})    [{'input': 'What did the cow say to the moon?', 'output': 'nothing at all'},     {'input': '2+4', 'output': '6'}]Create prompt template‚ÄãAssemble the prompt template, using the example_selector created above.from langchain.prompts import (    FewShotChatMessagePromptTemplate,    ChatPromptTemplate,)# Define the few-shot prompt.few_shot_prompt = FewShotChatMessagePromptTemplate(    # The input variables select the values to pass to the example_selector    input_variables=["input"],    example_selector=example_selector,    # Define how each example will be formatted.    # In this case, each example will become 2 messages:    # 1 human, and 1 AI    example_prompt=ChatPromptTemplate.from_messages(        [("human", "{input}"), ("ai", "{output}")]    ),)Below is an example of how this would be assembled.print(few_shot_prompt.format(input="What's 3+3?"))    Human: 2+3    AI: 5    Human: 2+2    AI: 4Assemble the final prompt template:final_prompt = ChatPromptTemplate.from_messages(    [        ("system", "You are a wondrous wizard of math."),        few_shot_prompt,        ("human", "{input}"),    ])print(few_shot_prompt.format(input="What's 3+3?"))    Human: 2+3    AI: 5    Human: 2+2    AI: 4Use with an LLM‚ÄãNow, you can connect your model to the few-shot prompt.from langchain.chat_models import ChatAnthropicchain = final_prompt | ChatAnthropic(temperature=0.0)chain.invoke({"input": "What's 3+3?"})    AIMessage(content=' 3 + 3 = 6', additional_kwargs={}, example=False)PreviousFew-shot prompt templatesNextFormat template outputFixed ExamplesDynamic few-shot promptingCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright ¬© 2023 LangChain, Inc.
This notebook covers how to use few-shot examples in chat models. There does not appear to be solid consensus on how best to do few-shot prompting, and the optimal prompt compilation will likely vary by model. Because of this, we provide few-shot prompt templates like the FewShotChatMessagePromptTemplate as a flexible starting point, and you can modify or replace them as you see fit.
This notebook covers how to use few-shot examples in chat models. There does not appear to be solid consensus on how best to do few-shot prompting, and the optimal prompt compilation will likely vary by model. Because of this, we provide few-shot prompt templates like the FewShotChatMessagePromptTemplate as a flexible starting point, and you can modify or replace them as you see fit. ->: "horse"})    [{'input': 'What did the cow say to the moon?', 'output': 'nothing at all'},     {'input': '2+4', 'output': '6'}]Create prompt template‚ÄãAssemble the prompt template, using the example_selector created above.from langchain.prompts import (    FewShotChatMessagePromptTemplate,    ChatPromptTemplate,)# Define the few-shot prompt.few_shot_prompt = FewShotChatMessagePromptTemplate(    # The input variables select the values to pass to the example_selector    input_variables=["input"],    example_selector=example_selector,    # Define how each example will be formatted.    # In this case, each example will become 2 messages:    # 1 human, and 1 AI    example_prompt=ChatPromptTemplate.from_messages(        [("human", "{input}"), ("ai", "{output}")]    ),)Below is an example of how this would be assembled.print(few_shot_prompt.format(input="What's 3+3?"))    Human: 2+3    AI: 5    Human: 2+2    AI: 4Assemble the final prompt template:final_prompt = ChatPromptTemplate.from_messages(    [        ("system", "You are a wondrous wizard of math."),        few_shot_prompt,        ("human", "{input}"),    ])print(few_shot_prompt.format(input="What's 3+3?"))    Human: 2+3    AI: 5    Human: 2+2    AI: 4Use with an LLM‚ÄãNow, you can connect your model to the few-shot prompt.from langchain.chat_models import ChatAnthropicchain = final_prompt | ChatAnthropic(temperature=0.0)chain.invoke({"input": "What's 3+3?"})    AIMessage(content=' 3 + 3 = 6', additional_kwargs={}, example=False)PreviousFew-shot prompt templatesNextFormat template outputFixed ExamplesDynamic few-shot promptingCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright ¬© 2023 LangChain, Inc.