0
0
LangChainframework~10 mins

Cost tracking across runs 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 class used for tracking costs in LangChain.

LangChain
from langchain.callbacks import [1]
Drag options to blanks, or click blank then click option'
AMemoryBuffer
BCallbackManager
CCostTracker
DRunLogger
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated classes like CallbackManager or MemoryBuffer.
Using a class name that does not exist in langchain.callbacks.
2fill in blank
medium

Complete the code to create a new cost tracker instance.

LangChain
tracker = [1]()
Drag options to blanks, or click blank then click option'
ARunManager
BCallbackHandler
CMemoryBuffer
DCostTracker
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated classes like RunManager or CallbackHandler.
Forgetting to instantiate the class.
3fill in blank
hard

Fix the error in the code to add the cost tracker to the callback manager.

LangChain
callback_manager = CallbackManager(callbacks=[[1]])
Drag options to blanks, or click blank then click option'
Atracker
BCostTracker
CCallbackHandler
Drun_manager
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the class name instead of the instance.
Passing unrelated variables.
4fill in blank
hard

Fill both blanks to update the cost tracker after a run and then print the total cost.

LangChain
tracker.[1](run)
print(tracker.[2])
Drag options to blanks, or click blank then click option'
Aon_run_end
Btotal_cost
Cstart_run
Dcost
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method that does not exist like 'start_run'.
Trying to print a method instead of a property.
5fill in blank
hard

Fill all three blanks to reset the cost tracker, run a new process, and then print the updated cost.

LangChain
tracker.[1]()
result = process.run(input)
tracker.[2](result)
print(tracker.[3])
Drag options to blanks, or click blank then click option'
Areset
Bon_run_end
Ctotal_cost
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to reset before running.
Using wrong method names for updating or printing cost.