mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 11:43:54 +00:00
(test) token_counter - prompt tokens == tokens from API
This commit is contained in:
parent
70376d3a4f
commit
a20331e47a
1 changed files with 22 additions and 1 deletions
|
@ -316,4 +316,25 @@ def test_token_counter():
|
||||||
pytest.fail(f"Error occurred: {e}")
|
pytest.fail(f"Error occurred: {e}")
|
||||||
|
|
||||||
|
|
||||||
test_token_counter()
|
# test_token_counter()
|
||||||
|
|
||||||
|
|
||||||
|
def test_token_counter_azure():
|
||||||
|
# test that prompt_tokens counted == prompt_tokens from Azure API
|
||||||
|
try:
|
||||||
|
messages = [{"role": "user", "content": "hi how are you what time is it"}]
|
||||||
|
tokens_counted = token_counter(model="gpt-3.5-turbo", messages=messages)
|
||||||
|
print("Tokens Counted=", tokens_counted)
|
||||||
|
|
||||||
|
response = litellm.completion(model="azure/chatgpt-v-2", messages=messages)
|
||||||
|
|
||||||
|
prompt_tokens = response.usage.prompt_tokens
|
||||||
|
|
||||||
|
print("Tokens from Azure API=", prompt_tokens)
|
||||||
|
|
||||||
|
assert prompt_tokens == tokens_counted
|
||||||
|
except:
|
||||||
|
pytest.fail(f"Error occurred: {e}")
|
||||||
|
|
||||||
|
|
||||||
|
# test_token_counter_azure()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue