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

Add a 5k token buffer before the end of the context window #1289

Merged
merged 1 commit into from
Mar 1, 2025

Conversation

mrubens
Copy link
Collaborator

@mrubens mrubens commented Mar 1, 2025

Context

Follow-up on #1275 to give more of a buffer, just because it's currently so painful to recover from the case where you go beyond the context window and tiktoken is not an exact estimate.

Implementation

This truncates when you're within 5,000 tokens of the end of the window.

How to Test

Get a conversation near the end and confirm you never make it to within 5,000 tokens of the end of the window.


Important

Introduces a 5,000 token buffer in index.ts to prevent exceeding the context window, with updated tests in sliding-window.test.ts.

  • Behavior:
    • Adds TOKEN_BUFFER constant in index.ts to introduce a 5,000 token buffer before the context window limit.
    • Modifies truncateConversationIfNeeded() in index.ts to truncate messages if within TOKEN_BUFFER of the token limit.
  • Tests:
    • Updates sliding-window.test.ts to reflect new buffer logic, ensuring truncation occurs when within 5,000 tokens of the limit.
    • Adds test case in sliding-window.test.ts to verify truncation when tokens are within TOKEN_BUFFER of the threshold.

This description was created by Ellipsis for 764d963. It will automatically update as commits are pushed.

@mrubens mrubens requested a review from cte as a code owner March 1, 2025 13:51
Copy link

changeset-bot bot commented Mar 1, 2025

⚠️ No Changeset found

Latest commit: 764d963

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 size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request labels Mar 1, 2025
@mrubens mrubens merged commit 8df6bdf into main Mar 1, 2025
16 checks passed
@mrubens mrubens deleted the truncation_token_buffer branch March 1, 2025 14:37
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:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant