Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookPrompt + LLMRAGMultiple chainsQuerying a SQL DBAgentsCode writingAdding memoryAdding moderationUsing toolsLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsMemoryAgentsCallbacksModulesSecurityGuidesMoreLangChain Expression LanguageCookbookMultiple chainsOn this pageMultiple chainsRunnables can easily be used to string together multiple Chainsfrom operator import itemgetterfrom langchain.chat_models import ChatOpenAIfrom langchain.prompts import ChatPromptTemplatefrom langchain.schema import StrOutputParserprompt1 = ChatPromptTemplate.from_template("what is the city {person} is from?")prompt2 = ChatPromptTemplate.from_template("what country is the city {city} in? respond in {language}")model = ChatOpenAI()chain1 = prompt1 | model | StrOutputParser()chain2 = {"city": chain1, "language": itemgetter("language")} | prompt2 | model | StrOutputParser()chain2.invoke({"person": "obama", "language": "spanish"})    'El pa√≠s donde se encuentra la ciudad de Honolulu, donde naci√≥ Barack Obama, el 44¬∫ Presidente de los Estados Unidos, es Estados Unidos. Honolulu se encuentra en la isla de Oahu, en el estado de Haw√°i.'from langchain.schema.runnable import RunnableMap, RunnablePassthroughprompt1 = ChatPromptTemplate.from_template("generate a {attribute} color. Return the name of the color and nothing else:")prompt2 = ChatPromptTemplate.from_template("what is a fruit of color: {color}. Return the name of the fruit and nothing else:")prompt3 = ChatPromptTemplate.from_template("what is a country with a flag that has the color: {color}. Return the name of the country and nothing else:")prompt4 = ChatPromptTemplate.from_template("What is the color of {fruit} and the flag of {country}?")model_parser = model |
Runnables can easily be used to string together multiple Chains
Runnables can easily be used to string together multiple Chains ->: Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookPrompt + LLMRAGMultiple chainsQuerying a SQL DBAgentsCode writingAdding memoryAdding moderationUsing toolsLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsMemoryAgentsCallbacksModulesSecurityGuidesMoreLangChain Expression LanguageCookbookMultiple chainsOn this pageMultiple chainsRunnables can easily be used to string together multiple Chainsfrom operator import itemgetterfrom langchain.chat_models import ChatOpenAIfrom langchain.prompts import ChatPromptTemplatefrom langchain.schema import StrOutputParserprompt1 = ChatPromptTemplate.from_template("what is the city {person} is from?")prompt2 = ChatPromptTemplate.from_template("what country is the city {city} in? respond in {language}")model = ChatOpenAI()chain1 = prompt1 | model | StrOutputParser()chain2 = {"city": chain1, "language": itemgetter("language")} | prompt2 | model | StrOutputParser()chain2.invoke({"person": "obama", "language": "spanish"})    'El pa√≠s donde se encuentra la ciudad de Honolulu, donde naci√≥ Barack Obama, el 44¬∫ Presidente de los Estados Unidos, es Estados Unidos. Honolulu se encuentra en la isla de Oahu, en el estado de Haw√°i.'from langchain.schema.runnable import RunnableMap, RunnablePassthroughprompt1 = ChatPromptTemplate.from_template("generate a {attribute} color. Return the name of the color and nothing else:")prompt2 = ChatPromptTemplate.from_template("what is a fruit of color: {color}. Return the name of the fruit and nothing else:")prompt3 = ChatPromptTemplate.from_template("what is a country with a flag that has the color: {color}. Return the name of the country and nothing else:")prompt4 = ChatPromptTemplate.from_template("What is the color of {fruit} and the flag of {country}?")model_parser = model |