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):        """Parse the output of an LLM call."""        return text.strip().split(", ")template = """You are a helpful assistant who generates comma separated lists.A user will pass in a category, and you should generate 5 objects in that category in a comma separated list.ONLY return a comma separated list, and nothing more."""human_template = "{text}"chat_prompt = ChatPromptTemplate.from_messages([    ("system", template),    ("human", human_template),])chain = chat_prompt | ChatOpenAI() | CommaSeparatedListOutputParser()chain.invoke({"text": "colors"})# >> ['red', 'blue', 'green', 'yellow', 'orange']Note that we are using the | syntax to join these components together.
This | syntax is called the LangChain Expression Language.
To learn more about this syntax, read the documentation here.Next steps‚ÄãThis is it!
We've now gone over how to create the core building block of LangChain applications.
There is a lot more nuance in all these components (LLMs, prompts, output parsers) and a lot more different components to learn about as well.
To continue on your journey:Dive deeper into LLMs, prompts, and output parsersLearn the other key componentsRead up on LangChain Expression Language to learn how to chain these components togetherCheck out our helpful guides for detailed walkthroughs on particular topicsExplore end-to-end use casesPreviousInstallationNextLangChain Expression Language (LCEL)InstallationEnvironment setupBuilding an applicationLLMsPrompt templatesOutput parsersPromptTemplate + LLM + OutputParserNext stepsCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright ¬© 2023 LangChain, Inc.
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(self, text: str):        """Parse the output of an LLM call."""        return text.strip().split(", ")template = """You are a helpful assistant who generates comma separated lists.A user will pass in a category, and you should generate 5 objects in that category in a comma separated list.ONLY return a comma separated list, and nothing more."""human_template = "{text}"chat_prompt = ChatPromptTemplate.from_messages([    ("system", template),    ("human", human_template),])chain = chat_prompt | ChatOpenAI() | CommaSeparatedListOutputParser()chain.invoke({"text": "colors"})# >> ['red', 'blue', 'green', 'yellow', 'orange']Note that we are using the | syntax to join these components together.
This | syntax is called the LangChain Expression Language.
To learn more about this syntax, read the documentation here.Next steps‚ÄãThis is it!
We've now gone over how to create the core building block of LangChain applications.
There is a lot more nuance in all these components (LLMs, prompts, output parsers) and a lot more different components to learn about as well.
To continue on your journey:Dive deeper into LLMs, prompts, and output parsersLearn the other key componentsRead up on LangChain Expression Language to learn how to chain these components togetherCheck out our helpful guides for detailed walkthroughs on particular topicsExplore end-to-end use casesPreviousInstallationNextLangChain Expression Language (LCEL)InstallationEnvironment setupBuilding an applicationLLMsPrompt templatesOutput parsersPromptTemplate + LLM + OutputParserNext stepsCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright ¬© 2023 LangChain, Inc.