0
0
LangChainframework~10 mins

Rate limiting and authentication 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 import the rate limiter from LangChain.

LangChain
from langchain.[1] import RateLimiter
Drag options to blanks, or click blank then click option'
Alimits
Brate_limit
Cutils
Drate_limiter
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'rate_limit' instead of 'rate_limiter' causes import error.
Using 'utils' imports unrelated utilities.
2fill in blank
medium

Complete the code to create a rate limiter allowing 5 calls per minute.

LangChain
limiter = RateLimiter(max_calls=[1], period=60)
Drag options to blanks, or click blank then click option'
A10
B5
C60
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Setting max_calls to 60 confuses period with calls.
Setting max_calls to 1 is too restrictive.
3fill in blank
hard

Fix the error in the authentication header to include the API key.

LangChain
headers = {"Authorization": "Bearer [1]"}
Drag options to blanks, or click blank then click option'
AAPI_KEY
Bapi_key
CApiKey
Dapikey
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'api_key' causes undefined variable error.
Using 'apikey' or 'ApiKey' is inconsistent with naming conventions.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that limits calls and checks if the user is authenticated.

LangChain
result = {user: data[1] for user, data in users.items() if data.get('authenticated') [2] True}
Drag options to blanks, or click blank then click option'
A.limit()
B==
C!=
D.filter()
Attempts:
3 left
💡 Hint
Common Mistakes
Using '.filter()' instead of '.limit()' causes attribute error.
Using '!=' instead of '==' reverses the authentication check.
5fill in blank
hard

Fill both blanks to create a dictionary comprehension that uppercases user IDs, stores tokens, and filters active users.

LangChain
tokens = {user[1]: data['token'] for user, data in users.items() if data['active'] [2] True}
Drag options to blanks, or click blank then click option'
A.upper()
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' in the third blank filters inactive users instead.
Adding a dot or method in the second blank causes syntax error.