(functionList: ExtendedTool[])
| 221 | } |
| 222 | |
| 223 | export function countToolTokens(functionList: ExtendedTool[]): number { |
| 224 | let totalTokens = 0; |
| 225 | |
| 226 | // Iterate through each tool in the functionList array |
| 227 | for (const tool of functionList) { |
| 228 | // Get the description and stringify the parameters of the tool |
| 229 | const description = tool.description; |
| 230 | const stringifiedParameters = JSON.stringify(tool.parameters, null, 2); // Pretty print the JSON string |
| 231 | |
| 232 | // Count the tokens in the description and stringified parameters using countStringTokens |
| 233 | const descriptionTokens = countStringTokens(description); |
| 234 | const parametersTokens = countStringTokens(stringifiedParameters); |
| 235 | |
| 236 | // Sum the tokens of the description and stringified parameters for this tool |
| 237 | totalTokens += descriptionTokens + parametersTokens; |
| 238 | } |
| 239 | |
| 240 | return totalTokens; |
| 241 | } |
| 242 | |
| 243 | export function estimateChatTokens( |
| 244 | task: LLMTask, |
no test coverage detected