Hi there,
I see a mismatch in tokens counting.
import tiktoken
print( tiktoken.encoding_for_model('gpt-3.5-turbo').encode('salute me!') )
# [19776, 1088, 757, 0] <--- 4 tokens
import openai
openai.api_key = '<<REDACTED>>'
response = openai.ChatCompletion.create(
model='gpt-3.5-turbo',
messages=[
{'role': 'system', 'content': 'salute me!'},
]
)
print(response)
#{
# "id": "<<REDACTED>>",
# "object": "chat.completion",
# "created": 1691063916,
# "model": "gpt-3.5-turbo-0613",
# "choices": [
# {
# "index": 0,
# "message": {
# "role": "assistant",
# "content": "Hello! How can I assist you today?"
# },
# "finish_reason": "stop"
# }
# ],
# "usage": {
# "prompt_tokens": 11, <--- 11 tokens?
# "completion_tokens": 9,
# "total_tokens": 20
# }
#}
Why is there a difference between tokenizer
’s nr of tokens and prompt_tokens
’s nr of tokens? 4 vs 11
How are tokens actually calculated?