Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

fix: anthropic token counter (#587)

Junrong Lin6df0552a85a1
diff --git a/camel/utils/token_counting.py b/camel/utils/token_counting.py
index 35fbe7871..ed7719418 100644
--- a/camel/utils/token_counting.py
+++ b/camel/utils/token_counting.py
@@ -296,9 +296,11 @@ class AnthropicTokenCounter(BaseTokenCounter):
Returns:
int: Number of tokens in the messages.
"""
- prompt = messages_to_prompt(messages, self.model_type)
-
- return self.client.count_tokens(prompt)
+ num_tokens = 0
+ for message in messages:
+ content = str(message["content"])
+ num_tokens += self.client.count_tokens(content)
+ return num_tokens
class LiteLLMTokenCounter: