Introduction
A PromptTemplate helps you create messages with blanks that you fill in later. It makes writing prompts easier and less error-prone.
Jump into concepts and practice - no test required
from langchain.prompts import PromptTemplate prompt = PromptTemplate( input_variables=["name"], template="Hello, {name}! Welcome to LangChain." )
prompt = PromptTemplate(
input_variables=["city"],
template="Tell me about the weather in {city}."
)prompt = PromptTemplate(
input_variables=["food", "drink"],
template="I like {food} with a glass of {drink}."
)prompt = PromptTemplate(
input_variables=[],
template="Hello! This is a fixed message."
)from langchain.prompts import PromptTemplate # Create a prompt template with one variable prompt = PromptTemplate( input_variables=["name"], template="Hello, {name}! How are you today?" ) # Fill in the variable to get the final prompt final_prompt = prompt.format(name="Alice") print(final_prompt)
PromptTemplate in langchain?PromptTemplate with a placeholder named name?from langchain.prompts import PromptTemplate
prompt = PromptTemplate.from_template("Hello, {name}!")
result = prompt.format(name="Alice")
print(result)from langchain.prompts import PromptTemplate
prompt = PromptTemplate.from_template("Hi, {user}!")
result = prompt.format(name="Bob")
print(result)PromptTemplate that asks for a user's name and age, then formats a greeting. Which code correctly defines and uses this template?