Here is an example below of doing that:from langchain.prompts import ChatPromptTemplateprompt = ChatPromptTemplate.from_messages([    ("system", "You are a helpful chatbot"),    ("human", "Tell me a joke about {topic}"),])You can then use this in a chain as follows:chain = prompt | modelchain.invoke({"topic": "bears"})How is the prompt actually being formatted under the hood? We can see that by running the following codeprompt_value = prompt.format_prompt(topic="bears")model.convert_prompt(prompt_value)This produces the following formatted string:'\n\nHuman: <admin>You are a helpful chatbot</admin>\n\nHuman: Tell me a joke about bears\n\nAssistant:'We can see that under the hood LangChain is representing SystemMessages with Human: <admin>...</admin>,
and is appending an assistant message to the end IF the last message is NOT already an assistant message.If you decide instead to use a normal PromptTemplate (one that just works on a single string) let's take a look at
what happens:from langchain.prompts import PromptTemplateprompt = PromptTemplate.from_template("Tell me a joke about {topic}")prompt_value = prompt.format_prompt(topic="bears")model.convert_prompt(prompt_value)This produces the following formatted string:'\n\nHuman: Tell me a joke about bears\n\nAssistant:'We can see that it automatically adds the Human and Assistant tags.
What is happening under the hood?
First: the string gets converted to a single human message. This happens generically (because we are using a subclass of ChatModel).
Then, similarly to the above example, an empty Assistant message is getting appended.
This is Anthropic specific.[Deprecated] Anthropic‚ÄãThis Anthropic wrapper is subclassed from LLM.
All functionality related to Anthropic models.
All functionality related to Anthropic models. ->: Here is an example below of doing that:from langchain.prompts import ChatPromptTemplateprompt = ChatPromptTemplate.from_messages([    ("system", "You are a helpful chatbot"),    ("human", "Tell me a joke about {topic}"),])You can then use this in a chain as follows:chain = prompt | modelchain.invoke({"topic": "bears"})How is the prompt actually being formatted under the hood? We can see that by running the following codeprompt_value = prompt.format_prompt(topic="bears")model.convert_prompt(prompt_value)This produces the following formatted string:'\n\nHuman: <admin>You are a helpful chatbot</admin>\n\nHuman: Tell me a joke about bears\n\nAssistant:'We can see that under the hood LangChain is representing SystemMessages with Human: <admin>...</admin>,
and is appending an assistant message to the end IF the last message is NOT already an assistant message.If you decide instead to use a normal PromptTemplate (one that just works on a single string) let's take a look at
what happens:from langchain.prompts import PromptTemplateprompt = PromptTemplate.from_template("Tell me a joke about {topic}")prompt_value = prompt.format_prompt(topic="bears")model.convert_prompt(prompt_value)This produces the following formatted string:'\n\nHuman: Tell me a joke about bears\n\nAssistant:'We can see that it automatically adds the Human and Assistant tags.
What is happening under the hood?
First: the string gets converted to a single human message. This happens generically (because we are using a subclass of ChatModel).
Then, similarly to the above example, an empty Assistant message is getting appended.
This is Anthropic specific.[Deprecated] Anthropic‚ÄãThis Anthropic wrapper is subclassed from LLM.