0
0
LangChainframework~10 mins

Why observability is essential for LLM apps in LangChain - Test Your Understanding

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

Complete the code to import the observability tool in LangChain.

LangChain
from langchain.[1] import get_openai_callback
Drag options to blanks, or click blank then click option'
Achains
Bmemory
Ccallbacks
Dprompts
Attempts:
3 left
💡 Hint
Common Mistakes
Importing from memory or chains instead of callbacks
Trying to import a non-existent module
2fill in blank
medium

Complete the code to start tracking LLM usage with a context manager.

LangChain
with get_openai_callback() as [1]:
    response = llm(prompt)
Drag options to blanks, or click blank then click option'
Asession
Btracker
Cmonitor
Dcallback
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated variable names like 'session' or 'tracker'
Not using a variable to capture the callback
3fill in blank
hard

Fix the error in printing the total tokens used after the LLM call.

LangChain
print(f"Total tokens used: { [1].total_tokens }")
Drag options to blanks, or click blank then click option'
Acallback().total_tokens
Bcallback
Ccallback.total_tokens
Dget_openai_callback.total_tokens
Attempts:
3 left
💡 Hint
Common Mistakes
Using the method name instead of the variable
Adding parentheses incorrectly
Putting the attribute outside the braces
4fill in blank
hard

Fill the blanks to create a dictionary that logs prompt and token count.

LangChain
log = { [1]: [2] for [3], [4] in data.items() }
Drag options to blanks, or click blank then click option'
Aprompt
Btokens
Ckey
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using prompt and tokens as loop variables
Swapping key and value
5fill in blank
hard

Fill all three blanks to filter logs for tokens greater than 100.

LangChain
filtered = {k: v for k, v in logs.items() if v [1] [2] and k [3] 'prompt'}
Drag options to blanks, or click blank then click option'
A>
B100
C!=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators
Confusing equality and inequality