"Chat Models takes a list of chat messages as input - this list commonly referred to as a prompt.\n",
"Typically this is not simply a hardcoded list of messages but rather a combination of a template, some examples, and user input.\n",
"LangChain provides several classes and functions to make constructing and working with prompts easy.\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "7647a621",
"metadata": {},
"outputs": [],
"source": [
"from langchain.prompts import (\n",
" ChatPromptTemplate,\n",
" PromptTemplate,\n",
" SystemMessagePromptTemplate,\n",
" AIMessagePromptTemplate,\n",
" HumanMessagePromptTemplate,\n",
")\n",
"from langchain.schema import (\n",
" AIMessage,\n",
" HumanMessage,\n",
" SystemMessage\n",
")"
]
},
{
"cell_type": "markdown",
"id": "acb4a2f6",
"metadata": {},
"source": [
"You can make use of templating by using a `MessagePromptTemplate`. You can build a `ChatPromptTemplate` from one or more `MessagePromptTemplates`. You can use `ChatPromptTemplate`'s `format_prompt` -- this returns a `PromptValue`, which you can convert to a string or Message object, depending on whether you want to use the formatted value as input to an llm or chat model.\n",