0
0
LangChainframework~10 mins

LangChain architecture overview - Interactive Code Practice

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

Complete the code to import the core LangChain class for building chains.

LangChain
from langchain.chains import [1]
Drag options to blanks, or click blank then click option'
AChain
BLLMChain
CPromptTemplate
DMemory
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing 'Chain' which is a base class but not commonly imported directly.
Choosing 'PromptTemplate' which is for prompts, not chains.
2fill in blank
medium

Complete the code to create a prompt template with a variable placeholder.

LangChain
from langchain.prompts import PromptTemplate

prompt = PromptTemplate(template="Hello, {name}!", input_variables=["[1]"])
Drag options to blanks, or click blank then click option'
Aname
Buser
Cinput
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using a placeholder that does not match the input variable name.
Using generic words like 'user' or 'input' that are not declared.
3fill in blank
hard

Fix the error in creating an LLMChain by filling the missing argument.

LangChain
from langchain.llms import OpenAI
from langchain.chains import LLMChain

llm = OpenAI()
chain = LLMChain(llm=llm, prompt=[1])
Drag options to blanks, or click blank then click option'
Aprompt_template
BPromptTemplate
Ctemplate
Dprompt
Attempts:
3 left
💡 Hint
Common Mistakes
Using the class name instead of the variable.
Using incorrect argument names.
4fill in blank
hard

Fill both blanks to create a simple memory-enabled chain that remembers previous inputs.

LangChain
from langchain.memory import [1]

memory = [2]()
chain = LLMChain(llm=llm, prompt=prompt, memory=memory)
Drag options to blanks, or click blank then click option'
AConversationBufferMemory
BConversationSummaryMemory
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing summary memory with buffer memory.
Using different names for import and instantiation.
5fill in blank
hard

Fill all three blanks to create a chain that uses an OpenAI LLM, a prompt template, and conversation memory.

LangChain
from langchain.llms import [1]
from langchain.prompts import [2]
from langchain.memory import [3]

llm = [1]()
prompt = [2](template="Say hello to {name}", input_variables=["name"])
memory = [3]()
chain = LLMChain(llm=llm, prompt=prompt, memory=memory)
Drag options to blanks, or click blank then click option'
AOpenAI
BPromptTemplate
CConversationBufferMemory
DLLMChain
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up class names or forgetting to import memory.
Using the chain class as an import in place of prompt or memory.