Code lab 13.1 – Custom prompt template
The Prompt template is a class representing the mechanism to manage and use prompts in LangChain. As with most templates, there is text provided, as well as variables that represent inputs to the template. Using the PromptTemplate
package to manage your prompts ensures that it works well within the LangChain ecosystem. This code builds off the code we completed in Chapter 8’s 8.3 code lab, and can be found in the CHAPTER13
directory of the GitHub repo as CHAPTER13-1_PROMPT_TEMPLATES.ipynb
.
As a refresher, this is the template we have used the most:
prompt = hub.pull("jclemens24/rag-prompt")
Printing this prompt out looks like this:
You are an assistant for question-answering tasks. Use the following pieces of retrieved context to answer the question. If you don't know the answer, just say that you don't know. Question: {question} Context: {context} Answer:
This is stored in the PromptTemplate
object...