Unnamed: 0
int64
0
4.66k
page content
stringlengths
23
2k
description
stringlengths
8
925
output
stringlengths
38
2.93k
0
Get started | 🦜�🔗 Langchain Skip to main content🦜�🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesMode...
Get started with LangChain
Get started with LangChain ->: Get started | 🦜�🔗 Langchain Skip to main content🦜�🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language...
1
Quickstart | 🦜️🔗 Langchain
Installation
Installation ->: Quickstart | 🦜️🔗 Langchain
2
Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/​ORetrievalChainsMemoryAgentsCallbac...
Installation
Installation ->: Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/​ORetrievalChainsMe...
3
Modules can be used as stand-alones in simple applications and they can be combined for more complex use cases.The most common and most important chain that LangChain helps create contains three things:LLM: The language model is the core reasoning engine here. In order to work with LangChain, you need to understand the...
Installation
Installation ->: Modules can be used as stand-alones in simple applications and they can be combined for more complex use cases.The most common and most important chain that LangChain helps create contains three things:LLM: The language model is the core reasoning engine here. In order to work with LangChain, you need ...
4
A ChatMessage has two required components:content: This is the content of the message.role: This is the role of the entity from which the ChatMessage is coming from.LangChain provides several objects to easily distinguish between different roles:HumanMessage: A ChatMessage coming from a human/user.AIMessage: A ChatMess...
Installation
Installation ->: A ChatMessage has two required components:content: This is the content of the message.role: This is the role of the entity from which the ChatMessage is coming from.LangChain provides several objects to easily distinguish between different roles:HumanMessage: A ChatMessage coming from a human/user.AIMe...
5
You can initialize them with parameters like temperature and others, and pass them around.Next, let's use the predict method to run over a string input.text = "What would be a good company name for a company that makes colorful socks?"llm.predict(text)# >> Feetful of Funchat_model.predict(text)# >> Socks O'ColorFinally...
Installation
Installation ->: You can initialize them with parameters like temperature and others, and pass them around.Next, let's use the predict method to run over a string input.text = "What would be a good company name for a company that makes colorful socks?"llm.predict(text)# >> Feetful of Funchat_model.predict(text)# >> Soc...
6
This can start off very simple - for example, a prompt to produce the above string would just be:from langchain.prompts import PromptTemplateprompt = PromptTemplate.from_template("What is a good name for a company that makes {product}?")prompt.format(product="colorful socks")What is a good name for a company that makes...
Installation
Installation ->: This can start off very simple - for example, a prompt to produce the above string would just be:from langchain.prompts import PromptTemplateprompt = PromptTemplate.from_template("What is a good name for a company that makes {product}?")prompt.format(product="colorful socks")What is a good name for a c...
7
There are few main type of OutputParsers, including:Convert text from LLM -> structured information (e.g. JSON)Convert a ChatMessage into just a stringConvert the extra information returned from a call besides the message (like OpenAI function invocation) into a string.For full information on this, see the section on o...
Installation
Installation ->: There are few main type of OutputParsers, including:Convert text from LLM -> structured information (e.g. JSON)Convert a ChatMessage into just a stringConvert the extra information returned from a call besides the message (like OpenAI function invocation) into a string.For full information on this, see...
8
Let's see it in action!from langchain.chat_models import ChatOpenAIfrom langchain.prompts.chat import ChatPromptTemplatefrom langchain.schema import BaseOutputParserclass CommaSeparatedListOutputParser(BaseOutputParser): """Parse the output of an LLM call to a comma-separated list.""" def parse(self, text: str): ...
Installation
Installation ->: Let's see it in action!from langchain.chat_models import ChatOpenAIfrom langchain.prompts.chat import ChatPromptTemplatefrom langchain.schema import BaseOutputParserclass CommaSeparatedListOutputParser(BaseOutputParser): """Parse the output of an LLM call to a comma-separated list.""" def parse(s...
9
Prompts | 🦜�🔗 Langchain Skip to main content🦜�🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/...
A prompt for a language model is a set of instructions or input provided by a user to
A prompt for a language model is a set of instructions or input provided by a user to ->: Prompts | 🦜�🔗 Langchain Skip to main content🦜�🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression Langu...
10
Example selectors | 🦜️🔗 Langchain Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?Modul...
If you have a large number of examples, you may need to select which ones to include in the prompt. The Example Selector is the class responsible for doing so.
If you have a large number of examples, you may need to select which ones to include in the prompt. The Example Selector is the class responsible for doing so. ->: Example selectors | 🦜️🔗 Langchain Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS Do...
11
Custom example selector | 🦜️🔗 Langchain
In this tutorial, we'll create a custom example selector that selects examples randomly from a given list of examples.
In this tutorial, we'll create a custom example selector that selects examples randomly from a given list of examples. ->: Custom example selector | 🦜️🔗 Langchain
12
Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/​OPromptsPrompt templatesExample sel...
In this tutorial, we'll create a custom example selector that selects examples randomly from a given list of examples.
In this tutorial, we'll create a custom example selector that selects examples randomly from a given list of examples. ->: Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageIn...
13
Take a look at the current set of example selector implementations supported in LangChain here.Implement custom example selector‚Äãfrom langchain.prompts.example_selector.base import BaseExampleSelectorfrom typing import Dict, Listimport numpy as npclass CustomExampleSelector(BaseExampleSelector): def __init__(s...
In this tutorial, we'll create a custom example selector that selects examples randomly from a given list of examples.
In this tutorial, we'll create a custom example selector that selects examples randomly from a given list of examples. ->: Take a look at the current set of example selector implementations supported in LangChain here.Implement custom example selector‚Äãfrom langchain.prompts.example_selector.base import BaseExampleSel...
14
Select by length | 🦜️🔗 Langchain
This example selector selects which examples to use based on length. This is useful when you are worried about constructing a prompt that will go over the length of the context window. For longer inputs, it will select fewer examples to include, while for shorter inputs it will select more.
This example selector selects which examples to use based on length. This is useful when you are worried about constructing a prompt that will go over the length of the context window. For longer inputs, it will select fewer examples to include, while for shorter inputs it will select more. ->: Select by length | ü¶úÔ...
15
Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/​OPromptsPrompt templatesExample sel...
This example selector selects which examples to use based on length. This is useful when you are worried about constructing a prompt that will go over the length of the context window. For longer inputs, it will select fewer examples to include, while for shorter inputs it will select more.
This example selector selects which examples to use based on length. This is useful when you are worried about constructing a prompt that will go over the length of the context window. For longer inputs, it will select fewer examples to include, while for shorter inputs it will select more. ->: Skip to main contentü¶ú...
16
is commented out because # it is provided as a default value if none is specified. # get_text_length: Callable[[str], int] = lambda x: len(re.split("\n| ", x)))dynamic_prompt = FewShotPromptTemplate( # We provide an ExampleSelector instead of examples. example_selector=example_selector, example_prompt=ex...
This example selector selects which examples to use based on length. This is useful when you are worried about constructing a prompt that will go over the length of the context window. For longer inputs, it will select fewer examples to include, while for shorter inputs it will select more.
This example selector selects which examples to use based on length. This is useful when you are worried about constructing a prompt that will go over the length of the context window. For longer inputs, it will select fewer examples to include, while for shorter inputs it will select more. ->: is commented out because...
17
Select by maximal marginal relevance (MMR) | 🦜️🔗 Langchain
The MaxMarginalRelevanceExampleSelector selects examples based on a combination of which examples are most similar to the inputs, while also optimizing for diversity. It does this by finding the examples with the embeddings that have the greatest cosine similarity with the inputs, and then iteratively adding them while...
The MaxMarginalRelevanceExampleSelector selects examples based on a combination of which examples are most similar to the inputs, while also optimizing for diversity. It does this by finding the examples with the embeddings that have the greatest cosine similarity with the inputs, and then iteratively adding them while...
18
Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/​OPromptsPrompt templatesExample sel...
The MaxMarginalRelevanceExampleSelector selects examples based on a combination of which examples are most similar to the inputs, while also optimizing for diversity. It does this by finding the examples with the embeddings that have the greatest cosine similarity with the inputs, and then iteratively adding them while...
The MaxMarginalRelevanceExampleSelector selects examples based on a combination of which examples are most similar to the inputs, while also optimizing for diversity. It does this by finding the examples with the embeddings that have the greatest cosine similarity with the inputs, and then iteratively adding them while...
19
similarity. OpenAIEmbeddings(), # The VectorStore class that is used to store the embeddings and do a similarity search over. FAISS, # The number of examples to produce. k=2,)mmr_prompt = FewShotPromptTemplate( # We provide an ExampleSelector instead of examples. example_selector=example_selector, ...
The MaxMarginalRelevanceExampleSelector selects examples based on a combination of which examples are most similar to the inputs, while also optimizing for diversity. It does this by finding the examples with the embeddings that have the greatest cosine similarity with the inputs, and then iteratively adding them while...
The MaxMarginalRelevanceExampleSelector selects examples based on a combination of which examples are most similar to the inputs, while also optimizing for diversity. It does this by finding the examples with the embeddings that have the greatest cosine similarity with the inputs, and then iteratively adding them while...
20
Select by n-gram overlap | 🦜️🔗 Langchain
The NGramOverlapExampleSelector selects and orders examples based on which examples are most similar to the input, according to an ngram overlap score. The ngram overlap score is a float between 0.0 and 1.0, inclusive.
The NGramOverlapExampleSelector selects and orders examples based on which examples are most similar to the input, according to an ngram overlap score. The ngram overlap score is a float between 0.0 and 1.0, inclusive. ->: Select by n-gram overlap | 🦜️🔗 Langchain
21
Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/​OPromptsPrompt templatesExample sel...
The NGramOverlapExampleSelector selects and orders examples based on which examples are most similar to the input, according to an ngram overlap score. The ngram overlap score is a float between 0.0 and 1.0, inclusive.
The NGramOverlapExampleSelector selects and orders examples based on which examples are most similar to the input, according to an ngram overlap score. The ngram overlap score is a float between 0.0 and 1.0, inclusive. ->: Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSm...
22
stops. # It is set to -1.0 by default. threshold=-1.0, # For negative threshold: # Selector sorts examples by ngram overlap score, and excludes none. # For threshold greater than 1.0: # Selector excludes all examples, and returns an empty list. # For threshold equal to 0.0: # Selector sorts exam...
The NGramOverlapExampleSelector selects and orders examples based on which examples are most similar to the input, according to an ngram overlap score. The ngram overlap score is a float between 0.0 and 1.0, inclusive.
The NGramOverlapExampleSelector selects and orders examples based on which examples are most similar to the input, according to an ngram overlap score. The ngram overlap score is a float between 0.0 and 1.0, inclusive. ->: stops. # It is set to -1.0 by default. threshold=-1.0, # For negative threshold: # Se...
23
it is excluded.example_selector.threshold = 0.0print(dynamic_prompt.format(sentence="Spot can run fast.")) Give the Spanish translation of every input Input: Spot can run. Output: Spot puede correr. Input: See Spot run. Output: Ver correr a Spot. Input: Spot plays fetch. Output: Spot ju...
The NGramOverlapExampleSelector selects and orders examples based on which examples are most similar to the input, according to an ngram overlap score. The ngram overlap score is a float between 0.0 and 1.0, inclusive.
The NGramOverlapExampleSelector selects and orders examples based on which examples are most similar to the input, according to an ngram overlap score. The ngram overlap score is a float between 0.0 and 1.0, inclusive. ->: it is excluded.example_selector.threshold = 0.0print(dynamic_prompt.format(sentence="Spot can run...
24
Select by similarity | 🦜️🔗 Langchain
This object selects examples based on similarity to the inputs. It does this by finding the examples with the embeddings that have the greatest cosine similarity with the inputs.
This object selects examples based on similarity to the inputs. It does this by finding the examples with the embeddings that have the greatest cosine similarity with the inputs. ->: Select by similarity | 🦜️🔗 Langchain
25
Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/​OPromptsPrompt templatesExample sel...
This object selects examples based on similarity to the inputs. It does this by finding the examples with the embeddings that have the greatest cosine similarity with the inputs.
This object selects examples based on similarity to the inputs. It does this by finding the examples with the embeddings that have the greatest cosine similarity with the inputs. ->: Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntro...
26
example_selector=example_selector, example_prompt=example_prompt, prefix="Give the antonym of every input", suffix="Input: {adjective}\nOutput:", input_variables=["adjective"],) Running Chroma using direct local API. Using DuckDB in-memory for database. Data will be transient.# Input is a feeling, so ...
This object selects examples based on similarity to the inputs. It does this by finding the examples with the embeddings that have the greatest cosine similarity with the inputs.
This object selects examples based on similarity to the inputs. It does this by finding the examples with the embeddings that have the greatest cosine similarity with the inputs. ->: example_selector=example_selector, example_prompt=example_prompt, prefix="Give the antonym of every input", suffix="Input: {adje...
27
Validate template | 🦜️🔗 Langchain Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?Modul...
By default, PromptTemplate will validate the template string by checking whether the inputvariables match the variables defined in template. You can disable this behavior by setting validatetemplate to False.
By default, PromptTemplate will validate the template string by checking whether the inputvariables match the variables defined in template. You can disable this behavior by setting validatetemplate to False. ->: Validate template | 🦜️🔗 Langchain Skip to main content🦜️🔗 LangChainDocsUse casesInteg...
28
Custom prompt template | 🦜️🔗 Langchain
Let's suppose we want the LLM to generate English language explanations of a function given its name. To achieve this task, we will create a custom prompt template that takes in the function name as input, and formats the prompt template to provide the source code of the function.
Let's suppose we want the LLM to generate English language explanations of a function given its name. To achieve this task, we will create a custom prompt template that takes in the function name as input, and formats the prompt template to provide the source code of the function. ->: Custom prompt template | ü¶úÔ∏èü...
29
Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/​OPromptsPrompt templatesConnecting ...
Let's suppose we want the LLM to generate English language explanations of a function given its name. To achieve this task, we will create a custom prompt template that takes in the function name as input, and formats the prompt template to provide the source code of the function.
Let's suppose we want the LLM to generate English language explanations of a function given its name. To achieve this task, we will create a custom prompt template that takes in the function name as input, and formats the prompt template to provide the source code of the function. ->: Skip to main content🦜️🔗 La...
30
attribute that exposes what input variables the prompt template expects.It defines a format method that takes in keyword arguments corresponding to the expected input_variables and returns the formatted prompt.We will create a custom prompt template that takes in the function name as input and formats the prompt to pro...
Let's suppose we want the LLM to generate English language explanations of a function given its name. To achieve this task, we will create a custom prompt template that takes in the function name as input, and formats the prompt template to provide the source code of the function.
Let's suppose we want the LLM to generate English language explanations of a function given its name. To achieve this task, we will create a custom prompt template that takes in the function name as input, and formats the prompt template to provide the source code of the function. ->: attribute that exposes what input ...
31
the custom prompt template‚ÄãNow that we have created a custom prompt template, we can use it to generate prompts for our task.fn_explainer = FunctionExplainerPromptTemplate(input_variables=["function_name"])# Generate a prompt for the function "get_source_code"prompt = fn_explainer.format(function_name=get_source_code...
Let's suppose we want the LLM to generate English language explanations of a function given its name. To achieve this task, we will create a custom prompt template that takes in the function name as input, and formats the prompt template to provide the source code of the function.
Let's suppose we want the LLM to generate English language explanations of a function given its name. To achieve this task, we will create a custom prompt template that takes in the function name as input, and formats the prompt template to provide the source code of the function. ->: the custom prompt template‚ÄãNow t...
32
Few-shot examples for chat models | 🦜️🔗 Langchain
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 ...
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 ...
33
Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/​OPromptsPrompt templatesConnecting ...
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 ...
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 ...
34
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.Below is a simple demonstration. First, import the modules for this example:from langchain.prompts import ( FewShotChatMessagePromptTemplate, ChatPromptTemplate,)Then, define...
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 ...
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 ...
35
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. ...
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 ...
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 ...
36
"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,)# Defi...
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 ...
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 ...
37
Types of MessagePromptTemplate | 🦜️🔗 Langchain
LangChain provides different types of MessagePromptTemplate. The most commonly used are AIMessagePromptTemplate, SystemMessagePromptTemplate and HumanMessagePromptTemplate, which create an AI message, system message and human message respectively.
LangChain provides different types of MessagePromptTemplate. The most commonly used are AIMessagePromptTemplate, SystemMessagePromptTemplate and HumanMessagePromptTemplate, which create an AI message, system message and human message respectively. ->: Types of MessagePromptTemplate | 🦜️🔗 Langchain
38
Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/​OPromptsPrompt templatesConnecting ...
LangChain provides different types of MessagePromptTemplate. The most commonly used are AIMessagePromptTemplate, SystemMessagePromptTemplate and HumanMessagePromptTemplate, which create an AI message, system message and human message respectively.
LangChain provides different types of MessagePromptTemplate. The most commonly used are AIMessagePromptTemplate, SystemMessagePromptTemplate and HumanMessagePromptTemplate, which create an AI message, system message and human message respectively. ->: Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAP...
39
in {word_count} words."human_message_template = HumanMessagePromptTemplate.from_template(human_prompt)chat_prompt = ChatPromptTemplate.from_messages([MessagesPlaceholder(variable_name="conversation"), human_message_template])human_message = HumanMessage(content="What is the best way to learn programming?")ai_message = ...
LangChain provides different types of MessagePromptTemplate. The most commonly used are AIMessagePromptTemplate, SystemMessagePromptTemplate and HumanMessagePromptTemplate, which create an AI message, system message and human message respectively.
LangChain provides different types of MessagePromptTemplate. The most commonly used are AIMessagePromptTemplate, SystemMessagePromptTemplate and HumanMessagePromptTemplate, which create an AI message, system message and human message respectively. ->: in {word_count} words."human_message_template = HumanMessagePromptTe...
40
Format template output | 🦜️🔗 Langchain
The output of the format method is available as a string, list of messages and ChatPromptValue
The output of the format method is available as a string, list of messages and ChatPromptValue ->: Format template output | 🦜️🔗 Langchain
41
Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/​OPromptsPrompt templatesConnecting ...
The output of the format method is available as a string, list of messages and ChatPromptValue
The output of the format method is available as a string, list of messages and ChatPromptValue ->: Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLan...
42
examples for chat modelsNextTemplate formatsCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright © 2023 LangChain, Inc.
The output of the format method is available as a string, list of messages and ChatPromptValue
The output of the format method is available as a string, list of messages and ChatPromptValue ->: examples for chat modelsNextTemplate formatsCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright © 2023 LangChain, Inc.
43
Composition | 🦜️🔗 Langchain
This notebook goes over how to compose multiple prompts together. This can be useful when you want to reuse parts of prompts. This can be done with a PipelinePrompt. A PipelinePrompt consists of two main parts:
This notebook goes over how to compose multiple prompts together. This can be useful when you want to reuse parts of prompts. This can be done with a PipelinePrompt. A PipelinePrompt consists of two main parts: ->: Composition | 🦜️🔗 Langchain
44
Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/​OPromptsPrompt templatesConnecting ...
This notebook goes over how to compose multiple prompts together. This can be useful when you want to reuse parts of prompts. This can be done with a PipelinePrompt. A PipelinePrompt consists of two main parts:
This notebook goes over how to compose multiple prompts together. This can be useful when you want to reuse parts of prompts. This can be done with a PipelinePrompt. A PipelinePrompt consists of two main parts: ->: Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS...
45
("start", start_prompt)]pipeline_prompt = PipelinePromptTemplate(final_prompt=full_prompt, pipeline_prompts=input_prompts)pipeline_prompt.input_variables ['example_a', 'person', 'example_q', 'input']print(pipeline_prompt.format( person="Elon Musk", example_q="What's your favorite car?", example_a="Tesla", ...
This notebook goes over how to compose multiple prompts together. This can be useful when you want to reuse parts of prompts. This can be done with a PipelinePrompt. A PipelinePrompt consists of two main parts:
This notebook goes over how to compose multiple prompts together. This can be useful when you want to reuse parts of prompts. This can be done with a PipelinePrompt. A PipelinePrompt consists of two main parts: ->: ("start", start_prompt)]pipeline_prompt = PipelinePromptTemplate(final_prompt=full_prompt, pipeline_promp...
46
Partial prompt templates | 🦜️🔗 Langchain
Like other methods, it can make sense to "partial" a prompt template - e.g. pass in a subset of the required values, as to create a new prompt template which expects only the remaining subset of values.
Like other methods, it can make sense to "partial" a prompt template - e.g. pass in a subset of the required values, as to create a new prompt template which expects only the remaining subset of values. ->: Partial prompt templates | 🦜️🔗 Langchain
47
Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/​OPromptsPrompt templatesConnecting ...
Like other methods, it can make sense to "partial" a prompt template - e.g. pass in a subset of the required values, as to create a new prompt template which expects only the remaining subset of values.
Like other methods, it can make sense to "partial" a prompt template - e.g. pass in a subset of the required values, as to create a new prompt template which expects only the remaining subset of values. ->: Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSea...
48
input_variables=["foo", "bar"])partial_prompt = prompt.partial(foo="foo");print(partial_prompt.format(bar="baz")) foobazYou can also just initialize the prompt with the partialed variables.prompt = PromptTemplate(template="{foo}{bar}", input_variables=["bar"], partial_variables={"foo": "foo"})print(prompt.format(bar...
Like other methods, it can make sense to "partial" a prompt template - e.g. pass in a subset of the required values, as to create a new prompt template which expects only the remaining subset of values.
Like other methods, it can make sense to "partial" a prompt template - e.g. pass in a subset of the required values, as to create a new prompt template which expects only the remaining subset of values. ->: input_variables=["foo", "bar"])partial_prompt = prompt.partial(foo="foo");print(partial_prompt.format(bar="baz"))...
49
Few-shot prompt templates | 🦜️🔗 Langchain
In this tutorial, we'll learn how to create a prompt template that uses few-shot examples. A few-shot prompt template can be constructed from either a set of examples, or from an Example Selector object.
In this tutorial, we'll learn how to create a prompt template that uses few-shot examples. A few-shot prompt template can be constructed from either a set of examples, or from an Example Selector object. ->: Few-shot prompt templates | 🦜️🔗 Langchain
50
Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/​OPromptsPrompt templatesConnecting ...
In this tutorial, we'll learn how to create a prompt template that uses few-shot examples. A few-shot prompt template can be constructed from either a set of examples, or from an Example Selector object.
In this tutorial, we'll learn how to create a prompt template that uses few-shot examples. A few-shot prompt template can be constructed from either a set of examples, or from an Example Selector object. ->: Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSe...
51
Who was the founder of craigslist?Intermediate answer: Craigslist was founded by Craig Newmark.Follow up: When was Craig Newmark born?Intermediate answer: Craig Newmark was born on December 6, 1952.So the final answer is: December 6, 1952""" }, { "question": "Who was the maternal grandfather of George Washington?"...
In this tutorial, we'll learn how to create a prompt template that uses few-shot examples. A few-shot prompt template can be constructed from either a set of examples, or from an Example Selector object.
In this tutorial, we'll learn how to create a prompt template that uses few-shot examples. A few-shot prompt template can be constructed from either a set of examples, or from an Example Selector object. ->: Who was the founder of craigslist?Intermediate answer: Craigslist was founded by Craig Newmark.Follow up: When w...
52
is: Muhammad AliFeed examples and formatter to FewShotPromptTemplate‚ÄãFinally, create a FewShotPromptTemplate object. This object takes in the few-shot examples and the formatter for the few-shot examples.prompt = FewShotPromptTemplate( examples=examples, example_prompt=example_prompt, suffix="Question: {inpu...
In this tutorial, we'll learn how to create a prompt template that uses few-shot examples. A few-shot prompt template can be constructed from either a set of examples, or from an Example Selector object.
In this tutorial, we'll learn how to create a prompt template that uses few-shot examples. A few-shot prompt template can be constructed from either a set of examples, or from an Example Selector object. ->: is: Muhammad AliFeed examples and formatter to FewShotPromptTemplate‚ÄãFinally, create a FewShotPromptTemplate o...
53
is the director of Casino Royale? Intermediate Answer: The director of Casino Royale is Martin Campbell. Follow up: Where is Martin Campbell from? Intermediate Answer: New Zealand. So the final answer is: No Question: Who was the father of Mary Ball Washington?Using an example selector‚ÄãFeed examples in...
In this tutorial, we'll learn how to create a prompt template that uses few-shot examples. A few-shot prompt template can be constructed from either a set of examples, or from an Example Selector object.
In this tutorial, we'll learn how to create a prompt template that uses few-shot examples. A few-shot prompt template can be constructed from either a set of examples, or from an Example Selector object. ->: is the director of Casino Royale? Intermediate Answer: The director of Casino Royale is Martin Campbell. F...
54
to the input: Who was the father of Mary Ball Washington? question: Who was the maternal grandfather of George Washington? answer: Are follow up questions needed here: Yes. Follow up: Who was the mother of George Washington? Intermediate answer: The mother of George Washington was Mary Ball Washington. ...
In this tutorial, we'll learn how to create a prompt template that uses few-shot examples. A few-shot prompt template can be constructed from either a set of examples, or from an Example Selector object.
In this tutorial, we'll learn how to create a prompt template that uses few-shot examples. A few-shot prompt template can be constructed from either a set of examples, or from an Example Selector object. ->: to the input: Who was the father of Mary Ball Washington? question: Who was the maternal grandfather of Georg...
55
Template formats | 🦜️🔗 Langchain Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?Module...
PromptTemplate by default uses Python f-string as its template format. However, it can also use other formats like jinja2, specified through the template_format argument.
PromptTemplate by default uses Python f-string as its template format. However, it can also use other formats like jinja2, specified through the template_format argument. ->: Template formats | 🦜️🔗 Langchain Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmi...
56
Connecting to a Feature Store | 🦜️🔗 Langchain
Feature stores are a concept from traditional machine learning that make sure data fed into models is up-to-date and relevant. For more on this, see here.
Feature stores are a concept from traditional machine learning that make sure data fed into models is up-to-date and relevant. For more on this, see here. ->: Connecting to a Feature Store | 🦜️🔗 Langchain
57
Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/​OPromptsPrompt templatesConnecting ...
Feature stores are a concept from traditional machine learning that make sure data fed into models is up-to-date and relevant. For more on this, see here.
Feature stores are a concept from traditional machine learning that make sure data fed into models is up-to-date and relevant. For more on this, see here. ->: Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuick...
58
need to update the path depending on where you stored itfeast_repo_path = "../../../../../my_feature_repo/feature_repo/"store = FeatureStore(repo_path=feast_repo_path)Prompts‚ÄãHere we will set up a custom FeastPromptTemplate. This prompt template will take in a driver id, look up their stats, and format those stats in...
Feature stores are a concept from traditional machine learning that make sure data fed into models is up-to-date and relevant. For more on this, see here.
Feature stores are a concept from traditional machine learning that make sure data fed into models is up-to-date and relevant. For more on this, see here. ->: need to update the path depending on where you stored itfeast_repo_path = "../../../../../my_feature_repo/feature_repo/"store = FeatureStore(repo_path=feast_repo...
59
joke about chickens at the end to make them feel better Here are the drivers stats: Conversation rate: 0.4745151400566101 Acceptance rate: 0.055561766028404236 Average Daily Trips: 936 Your response:Use in a chain‚ÄãWe can now use this in a chain, successfully creating a chain that achieves perso...
Feature stores are a concept from traditional machine learning that make sure data fed into models is up-to-date and relevant. For more on this, see here.
Feature stores are a concept from traditional machine learning that make sure data fed into models is up-to-date and relevant. For more on this, see here. ->: joke about chickens at the end to make them feel better Here are the drivers stats: Conversation rate: 0.4745151400566101 Acceptance rate: 0.0555617...
60
the "prod" workspace.import tectonworkspace = tecton.get_workspace("prod")feature_service = workspace.get_feature_service("user_transaction_metrics")Prompts‚ÄãHere we will set up a custom TectonPromptTemplate. This prompt template will take in a user_id , look up their stats, and format those stats into a prompt.Note t...
Feature stores are a concept from traditional machine learning that make sure data fed into models is up-to-date and relevant. For more on this, see here.
Feature stores are a concept from traditional machine learning that make sure data fed into models is up-to-date and relevant. For more on this, see here. ->: the "prod" workspace.import tectonworkspace = tecton.get_workspace("prod")feature_service = workspace.get_feature_service("user_transaction_metrics")Prompts‚ÄãHe...
61
in the last day, write a short congratulations message on their recent sales 2. If no transaction in the last day, but they had a transaction in the last 30 days, playfully encourage them to sell more. 3. Always add a silly joke about chickens at the end Here are the vendor's stats: Number of Transactio...
Feature stores are a concept from traditional machine learning that make sure data fed into models is up-to-date and relevant. For more on this, see here.
Feature stores are a concept from traditional machine learning that make sure data fed into models is up-to-date and relevant. For more on this, see here. ->: in the last day, write a short congratulations message on their recent sales 2. If no transaction in the last day, but they had a transaction in the last 30 d...
62
${avg_transcation}Your response:"""prompt = PromptTemplate.from_template(template)class FeatureformPromptTemplate(StringPromptTemplate): def format(self, **kwargs) -> str: user_id = kwargs.pop("user_id") fpf = client.features([("avg_transactions", "quickstart")], {"user": user_id}) return prompt...
Feature stores are a concept from traditional machine learning that make sure data fed into models is up-to-date and relevant. For more on this, see here.
Feature stores are a concept from traditional machine learning that make sure data fed into models is up-to-date and relevant. For more on this, see here. ->: ${avg_transcation}Your response:"""prompt = PromptTemplate.from_template(template)class FeatureformPromptTemplate(StringPromptTemplate): def format(self, **kw...
63
pydantic import Extrafrom langchain.prompts import PromptTemplate, StringPromptTemplatefrom azure.identity import AzureCliCredentialfrom azureml.featurestore import FeatureStoreClient, init_online_lookup, get_online_featuresclass AzureMLFeatureStorePromptTemplate(StringPromptTemplate, extra=Extra.allow): def __init_...
Feature stores are a concept from traditional machine learning that make sure data fed into models is up-to-date and relevant. For more on this, see here.
Feature stores are a concept from traditional machine learning that make sure data fed into models is up-to-date and relevant. For more on this, see here. ->: pydantic import Extrafrom langchain.prompts import PromptTemplate, StringPromptTemplatefrom azure.identity import AzureCliCredentialfrom azureml.featurestore imp...
64
obs) # populate prompt template output using the fetched feature values. kwargs["query"] = query kwargs["account_id"] = account_id kwargs["account_age"] = df["accountAge"][0] kwargs["account_country"] = df["accountCountry"][0] kwargs["payment_rejects_1d_per_user"] = df[...
Feature stores are a concept from traditional machine learning that make sure data fed into models is up-to-date and relevant. For more on this, see here.
Feature stores are a concept from traditional machine learning that make sure data fed into models is up-to-date and relevant. For more on this, see here. ->: obs) # populate prompt template output using the fetched feature values. kwargs["query"] = query kwargs["account_id"] = account_id ...
65
Feature StorePrerequisitesPromptsTestUse in a chainCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright © 2023 LangChain, Inc.
Feature stores are a concept from traditional machine learning that make sure data fed into models is up-to-date and relevant. For more on this, see here.
Feature stores are a concept from traditional machine learning that make sure data fed into models is up-to-date and relevant. For more on this, see here. ->: Feature StorePrerequisitesPromptsTestUse in a chainCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright © 2023 LangChain, Inc.
66
Serialization | 🦜️🔗 Langchain
It is often preferable to store prompts not as python code but as files. This can make it easy to share, store, and version prompts. This notebook covers how to do that in LangChain, walking through all the different types of prompts and the different serialization options.
It is often preferable to store prompts not as python code but as files. This can make it easy to share, store, and version prompts. This notebook covers how to do that in LangChain, walking through all the different types of prompts and the different serialization options. ->: Serialization | 🦜️🔗 Langchain
67
Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/​OPromptsPrompt templatesConnecting ...
It is often preferable to store prompts not as python code but as files. This can make it easy to share, store, and version prompts. This notebook covers how to do that in LangChain, walking through all the different types of prompts and the different serialization options.
It is often preferable to store prompts not as python code but as files. This can make it easy to share, store, and version prompts. This notebook covers how to do that in LangChain, walking through all the different types of prompts and the different serialization options. ->: Skip to main content🦜️🔗 LangChain...
68
load_promptPromptTemplate‚ÄãThis section covers examples for loading a PromptTemplate.Loading from YAML‚ÄãThis shows an example of loading a PromptTemplate from YAML.cat simple_prompt.yaml _type: prompt input_variables: ["adjective", "content"] template: Tell me a {adjective} joke about {content...
It is often preferable to store prompts not as python code but as files. This can make it easy to share, store, and version prompts. This notebook covers how to do that in LangChain, walking through all the different types of prompts and the different serialization options.
It is often preferable to store prompts not as python code but as files. This can make it easy to share, store, and version prompts. This notebook covers how to do that in LangChain, walking through all the different types of prompts and the different serialization options. ->: load_promptPromptTemplate‚ÄãThis section ...
69
of loading a few-shot example from YAML.cat few_shot_prompt.yaml _type: few_shot input_variables: ["adjective"] prefix: Write antonyms for the following words. example_prompt: _type: prompt input_variables: ["input", "output"] template: "Input: {inpu...
It is often preferable to store prompts not as python code but as files. This can make it easy to share, store, and version prompts. This notebook covers how to do that in LangChain, walking through all the different types of prompts and the different serialization options.
It is often preferable to store prompts not as python code but as files. This can make it easy to share, store, and version prompts. This notebook covers how to do that in LangChain, walking through all the different types of prompts and the different serialization options. ->: of loading a few-shot example from YAML.c...
70
antonyms for the following words. Input: happy Output: sad Input: tall Output: short Input: funny Output:Examples in the config‚ÄãThis shows an example of referencing the examples directly in the config.cat few_shot_prompt_examples_in.json { "_type": "few_shot", "input_var...
It is often preferable to store prompts not as python code but as files. This can make it easy to share, store, and version prompts. This notebook covers how to do that in LangChain, walking through all the different types of prompts and the different serialization options.
It is often preferable to store prompts not as python code but as files. This can make it easy to share, store, and version prompts. This notebook covers how to do that in LangChain, walking through all the different types of prompts and the different serialization options. ->: antonyms for the following words. ...
71
OutputParser‚ÄãThis shows an example of loading a prompt along with an OutputParser from a file.cat prompt_with_output_parser.json { "input_variables": [ "question", "student_answer" ], "output_parser": { "regex": "(.*?)\\nScore: (.*)", "output_keys": ...
It is often preferable to store prompts not as python code but as files. This can make it easy to share, store, and version prompts. This notebook covers how to do that in LangChain, walking through all the different types of prompts and the different serialization options.
It is often preferable to store prompts not as python code but as files. This can make it easy to share, store, and version prompts. This notebook covers how to do that in LangChain, walking through all the different types of prompts and the different serialization options. ->: OutputParser‚ÄãThis shows an example of l...
72
Prompt pipelining | 🦜️🔗 Langchain
The idea behind prompt pipelining is to provide a user friendly interface for composing different parts of prompts together. You can do this with either string prompts or chat prompts. Constructing prompts this way allows for easy reuse of components.
The idea behind prompt pipelining is to provide a user friendly interface for composing different parts of prompts together. You can do this with either string prompts or chat prompts. Constructing prompts this way allows for easy reuse of components. ->: Prompt pipelining | 🦜️🔗 Langchain
73
Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/​OPromptsPrompt templatesConnecting ...
The idea behind prompt pipelining is to provide a user friendly interface for composing different parts of prompts together. You can do this with either string prompts or chat prompts. Constructing prompts this way allows for easy reuse of components.
The idea behind prompt pipelining is to provide a user friendly interface for composing different parts of prompts together. You can do this with either string prompts or chat prompts. Constructing prompts this way allows for easy reuse of components. ->: Skip to main content🦜️🔗 LangChainDocsUse casesIntegratio...
74
language="spanish") '¿Por qué el futbolista llevaba un paraguas al partido?\n\nPorque pronosticaban lluvia de goles.'Chat prompt pipelining​A chat prompt is made up a of a list of messages. Purely for developer experience, we've added a convinient way to create these prompts. In this pipeline, each new element i...
The idea behind prompt pipelining is to provide a user friendly interface for composing different parts of prompts together. You can do this with either string prompts or chat prompts. Constructing prompts this way allows for easy reuse of components.
The idea behind prompt pipelining is to provide a user friendly interface for composing different parts of prompts together. You can do this with either string prompts or chat prompts. Constructing prompts this way allows for easy reuse of components. ->: language="spanish") '¿Por qué el futbolista llevaba un para...
75
Use a Message when there is no variables to be formatted, use a MessageTemplate when there are variables to be formatted. You can also use just a string (note: this will automatically get inferred as a HumanMessagePromptTemplate.)new_prompt = ( prompt + HumanMessage(content="hi") + AIMessage(content="what?") ...
The idea behind prompt pipelining is to provide a user friendly interface for composing different parts of prompts together. You can do this with either string prompts or chat prompts. Constructing prompts this way allows for easy reuse of components.
The idea behind prompt pipelining is to provide a user friendly interface for composing different parts of prompts together. You can do this with either string prompts or chat prompts. Constructing prompts this way allows for easy reuse of components. ->: Use a Message when there is no variables to be formatted, use a ...
76
Language models | 🦜️🔗 Langchain
LangChain provides interfaces and integrations for two types of models:
LangChain provides interfaces and integrations for two types of models: ->: Language models | 🦜️🔗 Langchain
77
Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/​OPromptsLanguage modelsLLMsChat mod...
LangChain provides interfaces and integrations for two types of models:
LangChain provides interfaces and integrations for two types of models: ->: Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Langu...
78
but if you're creating an application that should work with different types of models the shared interface can be helpful.PreviousSelect by similarityNextLLMsLLMs vs chat modelsCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright © 2023 LangChain, Inc.
LangChain provides interfaces and integrations for two types of models:
LangChain provides interfaces and integrations for two types of models: ->: but if you're creating an application that should work with different types of models the shared interface can be helpful.PreviousSelect by similarityNextLLMsLLMs vs chat modelsCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright ¬...
79
Chat models | 🦜️🔗 Langchain
Head to Integrations for documentation on built-in integrations with chat model providers.
Head to Integrations for documentation on built-in integrations with chat model providers. ->: Chat models | 🦜️🔗 Langchain
80
Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/​OPromptsLanguage modelsLLMsChat mod...
Head to Integrations for documentation on built-in integrations with chat model providers.
Head to Integrations for documentation on built-in integrations with chat model providers. ->: Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangCha...
81
The types of messages currently supported in LangChain are AIMessage, HumanMessage, SystemMessage, FunctionMessage and ChatMessage -- ChatMessage takes in an arbitrary role parameter. Most of the time, you'll just be dealing with HumanMessage, AIMessage, and SystemMessageLCEL‚ÄãChat models implement the Runnable interf...
Head to Integrations for documentation on built-in integrations with chat model providers.
Head to Integrations for documentation on built-in integrations with chat model providers. ->: The types of messages currently supported in LangChain are AIMessage, HumanMessage, SystemMessage, FunctionMessage and ChatMessage -- ChatMessage takes in an arbitrary role parameter. Most of the time, you'll just be dealing ...
82
process, discouraging it from fitting the noise and reducing the complexity of the model. This helps to improve the model's ability to generalize well and make accurate predictions on unseen data.chat.batch([messages]) [AIMessage(content="The purpose of model regularization is to prevent overfitting in machine learn...
Head to Integrations for documentation on built-in integrations with chat model providers.
Head to Integrations for documentation on built-in integrations with chat model providers. ->: process, discouraging it from fitting the noise and reducing the complexity of the model. This helps to improve the model's ability to generalize well and make accurate predictions on unseen data.chat.batch([messages]) [AI...
83
when a model becomes too complex and starts to memorize the training data instead of learning the underlying patterns. Regularization techniques help in reducing the complexity of the model by adding a penalty to the loss function. This penalty encourages the model to have smaller weights or fewer features, making it m...
Head to Integrations for documentation on built-in integrations with chat model providers.
Head to Integrations for documentation on built-in integrations with chat model providers. ->: when a model becomes too complex and starts to memorize the training data instead of learning the underlying patterns. Regularization techniques help in reducing the complexity of the model by adding a penalty to the loss fun...
84
'value': AIMessageChunk(content=' machine')}) RunLogPatch({'op': 'add', 'path': '/streamed_output/-', 'value': AIMessageChunk(content=' learning')}) RunLogPatch({'op': 'add', 'path': '/streamed_output/-', 'value': AIMessageChunk(content=' model')}) RunLogPatch({'op': 'add', 'path': '/s...
Head to Integrations for documentation on built-in integrations with chat model providers.
Head to Integrations for documentation on built-in integrations with chat model providers. ->: 'value': AIMessageChunk(content=' machine')}) RunLogPatch({'op': 'add', 'path': '/streamed_output/-', 'value': AIMessageChunk(content=' learning')}) RunLogPatch({'op': 'add', 'path': '/streamed_output/-',...
85
Over')}) RunLogPatch({'op': 'add', 'path': '/streamed_output/-', 'value': AIMessageChunk(content='fit')}) RunLogPatch({'op': 'add', 'path': '/streamed_output/-', 'value': AIMessageChunk(content='ting')}) RunLogPatch({'op': 'add', 'path': '/streamed_output/-', 'value': AIMessageChu...
Head to Integrations for documentation on built-in integrations with chat model providers.
Head to Integrations for documentation on built-in integrations with chat model providers. ->: Over')}) RunLogPatch({'op': 'add', 'path': '/streamed_output/-', 'value': AIMessageChunk(content='fit')}) RunLogPatch({'op': 'add', 'path': '/streamed_output/-', 'value': AIMessageChunk(content='ting...
86
'path': '/streamed_output/-', 'value': AIMessageChunk(content=' fluctuations')}) RunLogPatch({'op': 'add', 'path': '/streamed_output/-', 'value': AIMessageChunk(content=' in')}) RunLogPatch({'op': 'add', 'path': '/streamed_output/-', 'value': AIMessageChunk(content=' the')}) RunLogPatc...
Head to Integrations for documentation on built-in integrations with chat model providers.
Head to Integrations for documentation on built-in integrations with chat model providers. ->: 'path': '/streamed_output/-', 'value': AIMessageChunk(content=' fluctuations')}) RunLogPatch({'op': 'add', 'path': '/streamed_output/-', 'value': AIMessageChunk(content=' in')}) RunLogPatch({'op': 'add', ...
87
'path': '/streamed_output/-', 'value': AIMessageChunk(content=' techniques')}) RunLogPatch({'op': 'add', 'path': '/streamed_output/-', 'value': AIMessageChunk(content=' introduce')}) RunLogPatch({'op': 'add', 'path': '/streamed_output/-', 'value': AIMessageChunk(content=' a')}) RunLogP...
Head to Integrations for documentation on built-in integrations with chat model providers.
Head to Integrations for documentation on built-in integrations with chat model providers. ->: 'path': '/streamed_output/-', 'value': AIMessageChunk(content=' techniques')}) RunLogPatch({'op': 'add', 'path': '/streamed_output/-', 'value': AIMessageChunk(content=' introduce')}) RunLogPatch({'op': 'a...
88
'value': AIMessageChunk(content=' from')}) RunLogPatch({'op': 'add', 'path': '/streamed_output/-', 'value': AIMessageChunk(content=' becoming')}) RunLogPatch({'op': 'add', 'path': '/streamed_output/-', 'value': AIMessageChunk(content=' too')}) RunLogPatch({'op': 'add', 'path': '/stream...
Head to Integrations for documentation on built-in integrations with chat model providers.
Head to Integrations for documentation on built-in integrations with chat model providers. ->: 'value': AIMessageChunk(content=' from')}) RunLogPatch({'op': 'add', 'path': '/streamed_output/-', 'value': AIMessageChunk(content=' becoming')}) RunLogPatch({'op': 'add', 'path': '/streamed_output/-', ...
89
of')}) RunLogPatch({'op': 'add', 'path': '/streamed_output/-', 'value': AIMessageChunk(content=' over')}) RunLogPatch({'op': 'add', 'path': '/streamed_output/-', 'value': AIMessageChunk(content='fit')}) RunLogPatch({'op': 'add', 'path': '/streamed_output/-', 'value': AIMessageChun...
Head to Integrations for documentation on built-in integrations with chat model providers.
Head to Integrations for documentation on built-in integrations with chat model providers. ->: of')}) RunLogPatch({'op': 'add', 'path': '/streamed_output/-', 'value': AIMessageChunk(content=' over')}) RunLogPatch({'op': 'add', 'path': '/streamed_output/-', 'value': AIMessageChunk(content='fit'...
90
instead of capturing the underlying patterns and relationships. Regularization techniques introduce a penalty term to the model's objective function, which discourages the model from becoming too complex. This helps to control the model's complexity and reduces the risk of overfitting, leading to better performance on ...
Head to Integrations for documentation on built-in integrations with chat model providers.
Head to Integrations for documentation on built-in integrations with chat model providers. ->: instead of capturing the underlying patterns and relationships. Regularization techniques introduce a penalty term to the model's objective function, which discourages the model from becoming too complex. This helps to contro...
91
will be a message.from langchain.schema import ( AIMessage, HumanMessage, SystemMessage)chat([HumanMessage(content="Translate this sentence from English to French: I love programming.")]) AIMessage(content="J'adore la programmation.")OpenAI's chat model supports multiple messages as input. See here for more...
Head to Integrations for documentation on built-in integrations with chat model providers.
Head to Integrations for documentation on built-in integrations with chat model providers. ->: will be a message.from langchain.schema import ( AIMessage, HumanMessage, SystemMessage)chat([HumanMessage(content="Translate this sentence from English to French: I love programming.")]) AIMessage(content="J'ador...
92
RunInfo(run_id=UUID('0a70a0bf-c599-4f51-932a-c7d42202c984'))])You can recover things like token usage from this LLMResult:result.llm_output {'token_usage': {'prompt_tokens': 53, 'completion_tokens': 18, 'total_tokens': 71}, 'model_name': 'gpt-3.5-turbo'}PreviousTracking token usageNextCachingGet starte...
Head to Integrations for documentation on built-in integrations with chat model providers.
Head to Integrations for documentation on built-in integrations with chat model providers. ->: RunInfo(run_id=UUID('0a70a0bf-c599-4f51-932a-c7d42202c984'))])You can recover things like token usage from this LLMResult:result.llm_output {'token_usage': {'prompt_tokens': 53, 'completion_tokens': 18, 'total_to...
93
LLMChain | 🦜️🔗 Langchain Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I...
You can use the existing LLMChain in a very similar way to before - provide a prompt and a model.
You can use the existing LLMChain in a very similar way to before - provide a prompt and a model. ->: LLMChain | 🦜️🔗 Langchain Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Exp...
94
Prompts | 🦜️🔗 Langchain
Prompts for chat models are built around messages, instead of just plain text.
Prompts for chat models are built around messages, instead of just plain text. ->: Prompts | 🦜️🔗 Langchain
95
Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/​OPromptsLanguage modelsLLMsChat mod...
Prompts for chat models are built around messages, instead of just plain text.
Prompts for chat models are built around messages, instead of just plain text. ->: Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expressio...
96
more directly, you could create a PromptTemplate outside and then pass it in, e.g.:prompt=PromptTemplate( template="You are a helpful assistant that translates {input_language} to {output_language}.", input_variables=["input_language", "output_language"],)system_message_prompt = SystemMessagePromptTemplate(prompt...
Prompts for chat models are built around messages, instead of just plain text.
Prompts for chat models are built around messages, instead of just plain text. ->: more directly, you could create a PromptTemplate outside and then pass it in, e.g.:prompt=PromptTemplate( template="You are a helpful assistant that translates {input_language} to {output_language}.", input_variables=["input_langua...
97
Tracking token usage | 🦜️🔗 Langchain
This notebook goes over how to track your token usage for specific calls. It is currently only implemented for the OpenAI API.
This notebook goes over how to track your token usage for specific calls. It is currently only implemented for the OpenAI API. ->: Tracking token usage | 🦜️🔗 Langchain
98
Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/​OPromptsLanguage modelsLLMsAsync AP...
This notebook goes over how to track your token usage for specific calls. It is currently only implemented for the OpenAI API.
This notebook goes over how to track your token usage for specific calls. It is currently only implemented for the OpenAI API. ->: Skip to main content🦜️🔗 LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression La...
99
to the 0.23 power?" ) print(f"Total Tokens: {cb.total_tokens}") print(f"Prompt Tokens: {cb.prompt_tokens}") print(f"Completion Tokens: {cb.completion_tokens}") print(f"Total Cost (USD): ${cb.total_cost}") > Entering new AgentExecutor chain... I need to find out who Olivia Wilde's boyfriend...
This notebook goes over how to track your token usage for specific calls. It is currently only implemented for the OpenAI API.
This notebook goes over how to track your token usage for specific calls. It is currently only implemented for the OpenAI API. ->: to the 0.23 power?" ) print(f"Total Tokens: {cb.total_tokens}") print(f"Prompt Tokens: {cb.prompt_tokens}") print(f"Completion Tokens: {cb.completion_tokens}") print(f"Total ...