crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

Claude-3 model usage_metrics

Open jonny7737 opened this issue 1 year ago • 1 comments

I am building a crew trask/agent by task/agent (one at a time). This process works but is a little chatty. Chatty makes me curious about usage so I asked - response from crew.usage_metrics: {'total_tokens': 0, 'prompt_tokens': 0, 'completion_tokens': 0, 'successful_requests': 0}

How do I get usage stats when using a Claude-3 model?

jonny7737 avatar Apr 19 '24 16:04 jonny7737

I'm having the same issue. I looked at the code and I think I found where the issue lies.

In agent.py, there is this piece of code.

@model_validator(mode="after")
    def set_agent_executor(self) -> "Agent":
        """set agent executor is set."""
        if hasattr(self.llm, "model_name"):
            self.llm.callbacks = [
                TokenCalcHandler(self.llm.model_name, self._token_process)
            ]
        if not self.agent_executor:
            self.set_cache_handler(self.cache_handler)
        return self

In my case, if hasattr(self.llm, "model_name"): would return false since the Claude 3 model doesn't contain the model_name attribute.

I am using the langchain_aws ChatBedrock class to instantiate my LLM.

crewai version: 0.28.8 langchain-aws: 0.1.3

xssMociN avatar May 08 '24 13:05 xssMociN

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Aug 17 '24 12:08 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Aug 22 '24 12:08 github-actions[bot]