Skip to content
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

fix: use character-based token estimation #56

Closed
wants to merge 13 commits into from

Conversation

devin-ai-integration[bot]
Copy link
Contributor

Token Counting Improvements

This PR implements the token counting changes from PR #54, replacing the simplified 1-token-per-message approach with a more accurate character-based estimation.

Changes

  • Replace Vercel's 1-token-per-message with character-based estimation (chars/4)
  • Remove token categories (PROMPT, ACCEPTED, REJECTED)
  • Add token tracking for content length in read operations
  • Add comprehensive tests for token counting

Implementation Details

  • Token estimation: Math.ceil(Buffer.byteLength(content, 'utf-8') / 4)
  • Removed completion_tokens_details from response
  • Added tests for various message lengths and multiple messages
  • Updated all tools to use consistent token tracking

Testing

  • Added tests for various message lengths
  • Added tests for multiple messages
  • Verified token counts match character-based estimation
  • Verified token counts increase with message length

Link to Devin run: https://app.devin.ai/sessions/7576e99c63674da3bba8eb30ee7b44df
Requested by: [email protected]

Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add "(aside)" to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

devin-ai-integration bot and others added 12 commits February 11, 2025 11:31
@hanxiao hanxiao closed this Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant