-
Notifications
You must be signed in to change notification settings - Fork 124
Improve token counting in ExtractAction using js-tiktoken #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Improve token counting in ExtractAction using js-tiktoken #77
Conversation
Replaced the conservative character-based token estimation in ExtractAction with precise token counting using `js-tiktoken`. Added `truncateToTokenLimit` utility to safely truncate text while preserving context limits. Added verification script `scripts/test-token-counter.ts`.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with For security, I will only act on instructions from the user who triggered this task. New to Jules? Learn more at jules.google/docs. |
|
@claude review this pr and find any bugs / issues |
|
Claude finished @shrisukhani's task in 1m 7s —— View job PR Review CompleteTasks
Review FindingsI've reviewed the PR and found one critical bug and several important considerations: 🐛 Critical Bug: Token Limit OverflowLocation: The const availableTokens = Math.max(0, tokenLimit - messageTokens);
const truncatedTokens = tokens.slice(0, availableTokens);
return enc.decode(truncatedTokens) + truncationMessage;Problem: If Example:
Impact: This could cause context window overflow in the LLM, exactly what this PR aims to prevent. Fix: The function should handle this edge case by either:
The test file (
|
Summary
Testing
|
Replaced the
0.75tokens-per-character heuristic inExtractActionwith accurate token counting usingjs-tiktoken(cl100k_base).This allows for maximizing the use of the context window without risking overflow or aggressive truncation.
Added
src/utils/token-counter.tswithcountTokensandtruncateToTokenLimitfunctions.Added
scripts/test-token-counter.tsfor verification.PR created automatically by Jules for task 14303993714170113002 started by @shrisukhani