MCPcopy Index your code
hub / github.com/continuedev/continue / countChatHistoryTokens

Function countChatHistoryTokens

extensions/cli/src/util/tokenizer.ts:177–191  ·  view source on GitHub ↗
(
  chatHistory: ChatHistoryItem[],
  model: ModelConfig,
)

Source from the content-addressed store, hash-verified

175 * @returns The estimated total token count
176 */
177export function countChatHistoryTokens(
178 chatHistory: ChatHistoryItem[],
179 model: ModelConfig,
180): number {
181 let totalTokens = 0;
182
183 for (const historyItem of chatHistory) {
184 totalTokens += countChatHistoryItemTokens(historyItem, model);
185 }
186
187 // Add some overhead for message structure (roughly 3 tokens per message)
188 totalTokens += chatHistory.length * 3;
189
190 return totalTokens;
191}
192
193/**
194 * Calculate the percentage of context used

Callers 6

compactChatHistoryFunction · 0.85
shouldAutoCompactFunction · 0.85
handleAutoCompactionFunction · 0.85
useContextPercentageFunction · 0.85
countTotalInputTokensFunction · 0.85
tokenizer.test.tsFile · 0.85

Calls 1

Tested by

no test coverage detected