Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cpsievert committed Dec 19, 2024
1 parent da070a3 commit 8aa3604
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tests/test_tokens.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from chatlas import ChatOpenAI, Turn
from chatlas import ChatAnthropic, ChatGoogle, ChatOpenAI, Turn
from chatlas._openai import OpenAIAzureProvider, OpenAIProvider
from chatlas._tokens import token_usage, tokens_log, tokens_reset

Expand Down Expand Up @@ -26,10 +26,20 @@ def test_tokens_method():
)

assert chat.tokens(values="discrete") == [2, 10, 2, 10]

assert chat.tokens(values="cumulative") == [None, (2, 10), None, (14, 10)]


def test_token_count_method():
chat = ChatOpenAI(model="gpt-4o-mini")
assert chat.token_count("What is 1 + 1?") == 31

chat = ChatAnthropic(model="claude-3-5-sonnet-20241022")
assert chat.token_count("What is 1 + 1?") == 16

chat = ChatGoogle(model="gemini-1.5-flash")
assert chat.token_count("What is 1 + 1?") == 9


def test_usage_is_none():
tokens_reset()
assert token_usage() is None
Expand Down

0 comments on commit 8aa3604

Please sign in to comment.