Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the PromptTemplate class from LangChain.
LangChain
from langchain.prompts import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing it with 'Prompt' or 'Chain'.
Wrong module path.
✗ Incorrect
PromptTemplate is a core class in LangChain for defining prompts.
2fill in blank
mediumComplete the code to create a simple PromptTemplate instance.
LangChain
prompt = [1].from_template('Tell me a joke about {topic}')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting '.from_template'.
Using the wrong class.
✗ Incorrect
Use PromptTemplate.from_template() to create prompts easily.
3fill in blank
hardComplete the code to import LLMChain.
LangChain
from langchain.chains import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Chain' instead of 'LLMChain'.
Wrong import path.
✗ Incorrect
LLMChain combines an LLM and a prompt to form a chain.
4fill in blank
hardFill both blanks to create an LLMChain (assume llm is defined).
LangChain
chain = [1](llm=llm, prompt=prompt) response = chain.[2]('cats')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'invoke' (newer API) instead of 'run'.
Wrong parameters for LLMChain.
✗ Incorrect
Create with LLMChain(llm=llm, prompt=prompt) and run with chain.run().
5fill in blank
hardFill all three blanks for a complete simple LangChain example (assume imports and llm done).
LangChain
prompt = PromptTemplate.from_template('[1] {topic}') chain = LLMChain(llm=llm, prompt=prompt) print(chain.[2]('[3]'))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Wrong run method.
Mismatched input variable.
Incomplete template.
✗ Incorrect
Use a template string with variable, run the chain, and provide input like 'cats'.