Tokens count #1112
Replies: 4 comments
-
You could use callbacks now, but I want to add a better way to report on it adding this as feature accepted |
Beta Was this translation helpful? Give feedback.
-
@joaomdmoura Any update on this feature? Need this. btw, Awesome job! |
Beta Was this translation helpful? Give feedback.
-
crew = Crew( print(crew.usage_metrics) |
Beta Was this translation helpful? Give feedback.
-
I believe I found a bug in the By ensuring that only a single instance of I've opened a PR for this, but would like some help verifying this hypothesis please. Thanks everyone! Here's the modified method: @model_validator(mode="after")
def set_agent_executor(self) -> "Agent":
"""set agent executor is set."""
if hasattr(self.llm, "model_name"):
token_handler = TokenCalcHandler(self.llm.model_name, self._token_process)
# Ensure self.llm.callbacks is a list
if not isinstance(self.llm.callbacks, list):
self.llm.callbacks = []
# Check if an instance of TokenCalcHandler already exists in the list
if not any(isinstance(handler, TokenCalcHandler) for handler in self.llm.callbacks):
self.llm.callbacks.append(token_handler)
if not self.agent_executor:
if not self.cache_handler:
self.cache_handler = CacheHandler()
self.set_cache_handler(self.cache_handler)
return self |
Beta Was this translation helpful? Give feedback.
-
How to determine tokens usage ?
Beta Was this translation helpful? Give feedback.
All reactions