above, you could pass in an instance of MessagePromptTemplate or BaseMessage.from langchain.chat_models import ChatOpenAIfrom langchain.prompts import HumanMessagePromptTemplatefrom langchain.schema.messages import SystemMessagechat_template = ChatPromptTemplate.from_messages(    [        SystemMessage(            content=(                "You are a helpful assistant that re-writes the user's text to "                "sound more upbeat."            )        ),        HumanMessagePromptTemplate.from_template("{text}"),    ])llm = ChatOpenAI()llm(chat_template.format_messages(text='i dont like eating tasty things.'))    AIMessage(content='I absolutely love indulging in delicious treats!')This provides you with a lot of flexibility in how you construct your chat prompts.LCEL‚ÄãPromptTemplate and ChatPromptTemplate implement the Runnable interface, the basic building block of the LangChain Expression Language (LCEL). This means they support invoke, ainvoke, stream, astream, batch, abatch, astream_log calls.PromptTemplate accepts a dictionary (of the prompt variables) and returns a StringPromptValue. A ChatPromptTemplate accepts a dictionary and returns a ChatPromptValue.prompt_val = prompt_template.invoke({"adjective": "funny", "content": "chickens"})prompt_val    StringPromptValue(text='Tell me a joke')prompt_val.to_string()    'Tell me a joke'prompt_val.to_messages()    [HumanMessage(content='Tell me a joke')]chat_val = chat_template.invoke({"text": 'i dont like eating tasty things.'})chat_val.to_messages()    [SystemMessage(content="You are a helpful assistant that re-writes the user's text to sound more upbeat."),     HumanMessage(content='i dont like eating tasty things.')]chat_val.to_string()    "System: You are a helpful assistant that re-writes the user's text to sound more upbeat.\nHuman: i dont like eating tasty things."PreviousPromptsNextConnecting to a Feature
Prompt templates are pre-defined recipes for generating prompts for language models.
Prompt templates are pre-defined recipes for generating prompts for language models. ->: above, you could pass in an instance of MessagePromptTemplate or BaseMessage.from langchain.chat_models import ChatOpenAIfrom langchain.prompts import HumanMessagePromptTemplatefrom langchain.schema.messages import SystemMessagechat_template = ChatPromptTemplate.from_messages(    [        SystemMessage(            content=(                "You are a helpful assistant that re-writes the user's text to "                "sound more upbeat."            )        ),        HumanMessagePromptTemplate.from_template("{text}"),    ])llm = ChatOpenAI()llm(chat_template.format_messages(text='i dont like eating tasty things.'))    AIMessage(content='I absolutely love indulging in delicious treats!')This provides you with a lot of flexibility in how you construct your chat prompts.LCEL‚ÄãPromptTemplate and ChatPromptTemplate implement the Runnable interface, the basic building block of the LangChain Expression Language (LCEL). This means they support invoke, ainvoke, stream, astream, batch, abatch, astream_log calls.PromptTemplate accepts a dictionary (of the prompt variables) and returns a StringPromptValue. A ChatPromptTemplate accepts a dictionary and returns a ChatPromptValue.prompt_val = prompt_template.invoke({"adjective": "funny", "content": "chickens"})prompt_val    StringPromptValue(text='Tell me a joke')prompt_val.to_string()    'Tell me a joke'prompt_val.to_messages()    [HumanMessage(content='Tell me a joke')]chat_val = chat_template.invoke({"text": 'i dont like eating tasty things.'})chat_val.to_messages()    [SystemMessage(content="You are a helpful assistant that re-writes the user's text to sound more upbeat."),     HumanMessage(content='i dont like eating tasty things.')]chat_val.to_string()    "System: You are a helpful assistant that re-writes the user's text to sound more upbeat.\nHuman: i dont like eating tasty things."PreviousPromptsNextConnecting to a Feature