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 colorful socks?However, the advantages of using these over raw string formatting are several.
You can "partial" out variables - e.g. you can format only some of the variables at a time.
You can compose them together, easily combining different templates into a single prompt.
For explanations of these functionalities, see the section on prompts for more detail.PromptTemplates can also be used to produce a list of messages.
In this case, the prompt not only contains information about the content, but also each message (its role, its position in the list, etc)
Here, what happens most often is a ChatPromptTemplate is a list of ChatMessageTemplates.
Each ChatMessageTemplate contains instructions for how to format that ChatMessage - its role, and then also its content.
Let's take a look at this below:from langchain.prompts.chat import ChatPromptTemplatetemplate = "You are a helpful assistant that translates {input_language} to {output_language}."human_template = "{text}"chat_prompt = ChatPromptTemplate.from_messages([    ("system", template),    ("human", human_template),])chat_prompt.format_messages(input_language="English", output_language="French", text="I love programming.")[    SystemMessage(content="You are a helpful assistant that translates English to French.", additional_kwargs={}),    HumanMessage(content="I love programming.")]ChatPromptTemplates can also be constructed in other ways - see the section on prompts for more detail.Output parsers‚ÄãOutputParsers convert the raw output of an LLM into a format that can be used downstream.
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 company that makes colorful socks?However, the advantages of using these over raw string formatting are several.
You can "partial" out variables - e.g. you can format only some of the variables at a time.
You can compose them together, easily combining different templates into a single prompt.
For explanations of these functionalities, see the section on prompts for more detail.PromptTemplates can also be used to produce a list of messages.
In this case, the prompt not only contains information about the content, but also each message (its role, its position in the list, etc)
Here, what happens most often is a ChatPromptTemplate is a list of ChatMessageTemplates.
Each ChatMessageTemplate contains instructions for how to format that ChatMessage - its role, and then also its content.
Let's take a look at this below:from langchain.prompts.chat import ChatPromptTemplatetemplate = "You are a helpful assistant that translates {input_language} to {output_language}."human_template = "{text}"chat_prompt = ChatPromptTemplate.from_messages([    ("system", template),    ("human", human_template),])chat_prompt.format_messages(input_language="English", output_language="French", text="I love programming.")[    SystemMessage(content="You are a helpful assistant that translates English to French.", additional_kwargs={}),    HumanMessage(content="I love programming.")]ChatPromptTemplates can also be constructed in other ways - see the section on prompts for more detail.Output parsers‚ÄãOutputParsers convert the raw output of an LLM into a format that can be used downstream.