Skip to content

Commit

Permalink
fix: anthropic token counter (#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocss884 committed Jun 19, 2024
1 parent 0c78de6 commit 6df0552
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions camel/utils/token_counting.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,11 @@ def count_tokens_from_messages(self, messages: List[OpenAIMessage]) -> int:
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:
Expand Down

0 comments on commit 6df0552

Please sign in to comment.