* Count tokens in a single tool call function
(
toolCallFunction: { name?: string; arguments?: string } | undefined,
)
| 65 | * Count tokens in a single tool call function |
| 66 | */ |
| 67 | function countToolCallFunctionTokens( |
| 68 | toolCallFunction: { name?: string; arguments?: string } | undefined, |
| 69 | ): number { |
| 70 | if (!toolCallFunction) { |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | let tokenCount = 0; |
| 75 | tokenCount += encode(toolCallFunction.name ?? "").length + 10; // Function name and structure overhead |
| 76 | tokenCount += encode(toolCallFunction.arguments ?? "").length; // Arguments |
| 77 | return tokenCount; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Count tokens in tool call outputs |
no test coverage detected