based on the input. For this, you can replace the examples with an example_selector. The other components remain the same as above! To review, the dynamic few-shot prompt template would look like:example_selector: responsible for selecting few-shot examples (and the order in which they are returned) for a given input. These implement the BaseExampleSelector interface. A common example is the vectorstore-backed SemanticSimilarityExampleSelectorexample_prompt: convert each example into 1 or more messages through its format_messages method. A common example would be to convert each example into one human message and one AI message response, or a human message followed by a function call message.These once again can be composed with other messages and chat templates to assemble your final prompt.from langchain.prompts import SemanticSimilarityExampleSelectorfrom langchain.embeddings import OpenAIEmbeddingsfrom langchain.vectorstores import ChromaSince we are using a vectorstore to select examples based on semantic similarity, we will want to first populate the store.examples = [    {"input": "2+2", "output": "4"},    {"input": "2+3", "output": "5"},    {"input": "2+4", "output": "6"},    {"input": "What did the cow say to the moon?", "output": "nothing at all"},    {        "input": "Write me a poem about the moon",        "output": "One for the moon, and one for me, who are we to talk about the moon?",    },]to_vectorize = [" ".join(example.values()) for example in examples]embeddings = OpenAIEmbeddings()vectorstore = Chroma.from_texts(to_vectorize, embeddings, metadatas=examples)Create the example_selector‚ÄãWith a vectorstore created, you can create the example_selector. Here we will isntruct it to only fetch the top 2 examples.example_selector = SemanticSimilarityExampleSelector(    vectorstore=vectorstore,    k=2,)# The prompt template will load examples by passing the input do the `select_examples` methodexample_selector.select_examples({"input": "horse"})
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. ->: based on the input. For this, you can replace the examples with an example_selector. The other components remain the same as above! To review, the dynamic few-shot prompt template would look like:example_selector: responsible for selecting few-shot examples (and the order in which they are returned) for a given input. These implement the BaseExampleSelector interface. A common example is the vectorstore-backed SemanticSimilarityExampleSelectorexample_prompt: convert each example into 1 or more messages through its format_messages method. A common example would be to convert each example into one human message and one AI message response, or a human message followed by a function call message.These once again can be composed with other messages and chat templates to assemble your final prompt.from langchain.prompts import SemanticSimilarityExampleSelectorfrom langchain.embeddings import OpenAIEmbeddingsfrom langchain.vectorstores import ChromaSince we are using a vectorstore to select examples based on semantic similarity, we will want to first populate the store.examples = [    {"input": "2+2", "output": "4"},    {"input": "2+3", "output": "5"},    {"input": "2+4", "output": "6"},    {"input": "What did the cow say to the moon?", "output": "nothing at all"},    {        "input": "Write me a poem about the moon",        "output": "One for the moon, and one for me, who are we to talk about the moon?",    },]to_vectorize = [" ".join(example.values()) for example in examples]embeddings = OpenAIEmbeddings()vectorstore = Chroma.from_texts(to_vectorize, embeddings, metadatas=examples)Create the example_selector‚ÄãWith a vectorstore created, you can create the example_selector. Here we will isntruct it to only fetch the top 2 examples.example_selector = SemanticSimilarityExampleSelector(    vectorstore=vectorstore,    k=2,)# The prompt template will load examples by passing the input do the `select_examples` methodexample_selector.select_examples({"input": "horse"})