Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a prompt template with a variable called 'name'.
LangChain
from langchain.prompts import PromptTemplate prompt = PromptTemplate(input_variables=["name"], template="Hello, [1]!")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name in the template that is not listed in input_variables.
Forgetting to use curly braces around the variable in the template.
✗ Incorrect
The variable in the template must match the input variable name, which is 'name'.
2fill in blank
mediumComplete the code to chain two prompts where the output of the first is input to the second.
LangChain
from langchain.chains import SimpleSequentialChain chain = SimpleSequentialChain(chains=[chain1, [1]])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a chain variable that is not defined.
Mixing the order of chains.
✗ Incorrect
To chain two prompts, you list the chains in order. The second chain is 'chain2'.
3fill in blank
hardFix the error in the prompt template by completing the missing input variable.
LangChain
prompt = PromptTemplate(input_variables=[[1]], template="What is the capital of {country}?")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Listing a variable in input_variables that is not used in the template.
Forgetting to include the variable used in the template.
✗ Incorrect
The template uses {country}, so 'country' must be in input_variables.
4fill in blank
hardFill both blanks to create a chain that takes input 'question' and outputs 'answer'.
LangChain
from langchain.chains import LLMChain chain = LLMChain(llm=llm, prompt=prompt, output_key=[1], input_key=[2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping input_key and output_key values.
Using keys that don't match the prompt variables.
✗ Incorrect
The output_key should be 'answer' and input_key should be 'question' to match the chain's data flow.
5fill in blank
hardFill all three blanks to create a prompt template with variables 'topic' and 'style', and chain them correctly.
LangChain
from langchain.prompts import PromptTemplate from langchain.chains import SimpleSequentialChain prompt1 = PromptTemplate(input_variables=[[1]], template="Write about [2].") prompt2 = PromptTemplate(input_variables=["style"], template="Make it [3].") chain1 = LLMChain(llm=llm, prompt=prompt1) chain2 = LLMChain(llm=llm, prompt=prompt2) chain = SimpleSequentialChain(chains=[chain1, chain2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting variable names in input_variables list.
Mismatching variable names between template and input_variables.
✗ Incorrect
input_variables must be a list of strings, so 'topic' is in quotes. The template uses {{topic}} and {{style}} variables.