Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

cte
Copy link
Collaborator

@cte cte commented Apr 29, 2025

Context

There does seem to be some benefit to offloading tiktoken in a web worker, especially for thinking models on older hardware. This is a slightly different take on @samhvw8's original implementation in #2848. I used an existing library (workerpool) for simplicity.

Implementation

Screenshots

before after

How to Test

Get in Touch


Important

Introduces worker-based token counting using workerpool, updates BaseProvider to utilize it, and adds tests for the tiktoken function.

  • Behavior:
    • Introduces worker-based token counting using workerpool in countTokens.ts.
    • Updates BaseProvider in base-provider.ts to use countTokens with workers.
    • Adds tiktoken function in tiktoken.ts for token counting.
  • Testing:
    • Adds tests for tiktoken in tiktoken.test.ts to verify token counting for text and image content.
  • Dependencies:
    • Adds workerpool as a dependency in package.json.
  • Configuration:
    • Updates esbuild.js to include worker configuration for countTokens.ts.
    • Modifies knip.json to ignore src/workers/**.

This description was created by Ellipsis for 8224d4c. You can customize this summary. It will automatically update as commits are pushed.

Copy link

changeset-bot bot commented Apr 29, 2025

⚠️ No Changeset found

Latest commit: 8224d4c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Apr 29, 2025
src/utils/countTokens.ts Show resolved Hide resolved
src/utils/countTokens.ts Show resolved Hide resolved
src/utils/__tests__/tiktoken.test.ts Show resolved Hide resolved
@dosubot dosubot bot added the enhancement New feature or request label Apr 29, 2025
@RooCodeInc RooCodeInc deleted a comment from ellipsis-dev bot Apr 29, 2025
@cte cte merged commit 65cb924 into main Apr 29, 2025
14 checks passed
@cte cte deleted the cte/count-tokens-worker branch April 29, 2025 19:29
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.