Hi,
I am trying to understand how prompt_tokens
are calculated for one/multiple tool_calls
and corresponding tool
messages.
Here is an example with a single tool call and a single tool message:
{
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "How much is 2 plus 2?"
}
]
},
{
"role": "assistant",
"tool_calls": [
{
"id": "a",
"type": "function",
"function": {
"name": "calculator",
"arguments": "{\"a\":2, \"b\":2}"
}
}
]
},
{
"role": "tool",
"tool_call_id": "a",
"content": "4"
}
]
}
In response I am getting "prompt_tokens": 40
.
If I copy/paste the same tool call and tool message (1 user message, 2 tool calls and 2 tool messages in total), I am getting 89 tokens, so the cost of a single (function call+tool message) pair seems to be 49 tokens.
But If I copy/paste them again (1 user message, 3 tool calls and 3 tool messages in total), I will get 114 tokens, which means that an additional (function call+tool message) pair costs 25 tokens. If I go further with 4/5/etc pairs, the cost is increased each time by 25.
So when the number of tool calls changes from 1 to 2, the cost of a second tool call is doubled for some reason. Is it a bug?
Thanks!