-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Clamp default model max tokens to 20% of context window #6761
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,9 +90,9 @@ export const getModelMaxOutputTokens = ({ | |
| return ANTHROPIC_DEFAULT_MAX_TOKENS | ||
| } | ||
|
|
||
| // If model has explicit maxTokens and it's not the full context window, use it | ||
| if (model.maxTokens && model.maxTokens !== model.contextWindow) { | ||
| return model.maxTokens | ||
| // If model has explicit maxTokens, clamp it to 20% of the context window | ||
| if (model.maxTokens) { | ||
| return Math.min(model.maxTokens, model.contextWindow * 0.2) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this magic number intentional? Would it be beneficial to make this configurable or at least define it as a named constant like for better maintainability? Also, consider adding a comment explaining why 20% was chosen as the threshold to help future developers understand the reasoning. |
||
| } | ||
|
|
||
| // For non-Anthropic formats without explicit maxTokens, return undefined | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed the previous comment check was removed. Is the current behavior intentional for models where maxTokens equals contextWindow? They would now be clamped to 20% as well.
Could we add a test case to verify this edge case behavior is as expected?