0
0
LangChainframework~10 mins

Partial prompt templates in LangChain - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Aname
Bage
Clocation
Dhobby
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated variables like 'age' or 'location' in the greeting.
2fill in blank
medium

Complete 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'
Aname
Bage
Clocation
Dhobby
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'name' instead of 'age' in the age placeholder.
3fill in blank
hard

Fix 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'
Aformat
Bcopy
Cpartial
Dreplace
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'copy' or 'format' which do not fix variables in the prompt.
4fill in blank
hard

Fill 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'
Apartial
Bformat
Ccopy
Drender
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'copy' instead of 'partial' or 'render' instead of 'format'.
5fill in blank
hard

Fill 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'
Apartial
Bformat
Cformatted
Dresult
Attempts:
3 left
💡 Hint
Common Mistakes
Printing the wrong variable or using incorrect methods for partial or formatting.