0
0
LangChainframework~10 mins

Variables and dynamic content 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 variable that stores a user's name.

LangChain
user_name = [1]
Drag options to blanks, or click blank then click option'
AAlice
Bname
C"Alice"
Duser
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around text
Using variable names instead of text
2fill in blank
medium

Complete the code to insert a variable into a prompt string using f-string syntax.

LangChain
prompt = f"Hello, [1]! How can I help you today?"
Drag options to blanks, or click blank then click option'
Aname
Buser_name
C"user_name"
Dusername
Attempts:
3 left
💡 Hint
Common Mistakes
Putting quotes around the variable inside the f-string
Using a different variable name than defined
3fill in blank
hard

Fix the error in the code to correctly create a prompt with dynamic content.

LangChain
prompt = f"Your order number is [1]."
Drag options to blanks, or click blank then click option'
Aorder-num
B"order_number"
CorderNumber
Dorder_number
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the variable name
Using a variable name with invalid characters
4fill in blank
hard

Fill both blanks to create a dictionary with variable keys and values.

LangChain
data = { [1]: [2] }
Drag options to blanks, or click blank then click option'
A"user_id"
Buser_id
C12345
D"12345"
Attempts:
3 left
💡 Hint
Common Mistakes
Using variables without quotes as keys
Using numbers without quotes when strings are needed
5fill in blank
hard

Fill all three blanks to create a prompt template with variables and a condition.

LangChain
prompt = f"Hello, [1]! Your balance is [2]. [3]"
Drag options to blanks, or click blank then click option'
Auser_name
Bbalance
C"Please pay soon."
D"Thank you for your payment.%"
Attempts:
3 left
💡 Hint
Common Mistakes
Putting quotes around variable names inside the f-string
Forgetting to quote the message string