MCPcopy Create free account
hub / github.com/Xyntopia/taskyon / countToolTokens

Function countToolTokens

src/modules/chat.ts:223–241  ·  view source on GitHub ↗
(functionList: ExtendedTool[])

Source from the content-addressed store, hash-verified

221}
222
223export 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
243export function estimateChatTokens(
244 task: LLMTask,

Callers 1

estimateChatTokensFunction · 0.85

Calls 1

countStringTokensFunction · 0.85

Tested by

no test coverage detected