Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a partial prompt template with a fixed variable.
LangChain
from langchain.prompts import PromptTemplate partial_prompt = PromptTemplate.from_template("Hello, my name is [1].")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated variables like 'age' or 'location' in the greeting.
✗ Incorrect
The variable 'name' fits the template context for introducing yourself.
2fill in blank
mediumComplete the code to create a partial prompt template with a fixed variable value.
LangChain
from langchain.prompts import PromptTemplate partial_prompt = PromptTemplate( input_variables=["name", "age"], template="My name is {name} and I am [1] years old." )
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'name' instead of 'age' in the age placeholder.
✗ Incorrect
The template refers to the age variable for the years old part.
3fill in blank
hardFix the error in the code by filling the missing method to create a partial prompt template.
LangChain
from langchain.prompts import PromptTemplate base_prompt = PromptTemplate(template="Hello {name}, you are {age} years old.", input_variables=["name", "age"]) partial_prompt = base_prompt.[1](partial_variables={"name": "Alice"})
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'copy' or 'format' which do not fix variables in the prompt.
✗ Incorrect
The 'partial' method creates a new prompt with some variables fixed.
4fill in blank
hardFill both blanks to create a partial prompt template and format it with the remaining variable.
LangChain
from langchain.prompts import PromptTemplate base_prompt = PromptTemplate(template="Hello {name}, you live in {city}.", input_variables=["name", "city"]) partial_prompt = base_prompt.[1](partial_variables={"name": "Bob"}) result = partial_prompt.[2]({"city": "Paris"})
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'copy' instead of 'partial' or 'render' instead of 'format'.
✗ Incorrect
Use 'partial' to fix 'name', then 'format' to fill 'city' and get the final string.
5fill in blank
hardFill all three blanks to create a partial prompt, format it, and print the result.
LangChain
from langchain.prompts import PromptTemplate base_prompt = PromptTemplate(template="{greeting}, {name}! Welcome to {place}.", input_variables=["greeting", "name", "place"]) partial_prompt = base_prompt.[1](partial_variables={"greeting": "Hi"}) formatted = partial_prompt.[2]({{"name": "Eve", "place": "Wonderland"}}) print([3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Printing the wrong variable or using incorrect methods for partial or formatting.
✗ Incorrect
Use 'partial' to fix greeting, 'format' to fill name and place, then print the formatted string.