Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a PromptTemplate with a template string.
LangChain
from langchain import PromptTemplate template = "Hello, my name is {name}." prompt = PromptTemplate(template=[1], input_variables=["name"])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the template string.
Using single quotes without curly braces for variables.
✗ Incorrect
The template string must be passed as a string with curly braces for variables, so it needs to be quoted properly.
2fill in blank
mediumComplete the code to specify the input variables for the PromptTemplate.
LangChain
from langchain import PromptTemplate prompt = PromptTemplate(template="Hello, {name}!", input_variables=[1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string instead of a list.
Using curly braces which create a set, not a list.
✗ Incorrect
input_variables must be a list of strings, so it needs to be in square brackets.
3fill in blank
hardFix the error in the code to correctly create a PromptTemplate with two input variables.
LangChain
from langchain import PromptTemplate template = "My name is {name} and I am {age} years old." prompt = PromptTemplate(template=template, input_variables=[1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting variable names inside the list.
Using curly braces which create a set, not a list.
✗ Incorrect
input_variables must be a list of strings with variable names quoted.
4fill in blank
hardFill both blanks to create a PromptTemplate and format it with variables.
LangChain
from langchain import PromptTemplate prompt = PromptTemplate(template=[1], input_variables=["animal", "sound"]) result = prompt.format(**[2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a set instead of a dictionary to format.
Not using curly braces in the template string.
✗ Incorrect
The template string must have placeholders, and format expects a dictionary with keys matching input_variables.
5fill in blank
hardFill all three blanks to create a PromptTemplate, format it, and print the result.
LangChain
from langchain import PromptTemplate prompt = PromptTemplate(template=[1], input_variables=["city", "weather"]) result = prompt.format(**[2]) print([3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Printing the dictionary instead of the formatted result.
Not using curly braces in the template string.
✗ Incorrect
The template string uses placeholders, format gets a dictionary, and print outputs the formatted string.