fix: add batching support for BanCompetitors to handle long input text #272
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Change Description
Previously, the
BanCompetitors
class failed to work with long text because it attempted to process the entire input text in a single request. This caused incomplete processing when the input text exceeded the model's token limit as it truncates input text.This PR introduces batching logic to split the input text into manageable chunks before sending it to the model. This ensures that
BanCompetitors
works correctly even with long inputs and models that have lower token limits. Also added a test case for long text that fail for old code and now it pass correctly.Assumptions:
For fast processing I used approximate token count equation that I already mentioned in the code
1 word ~ 4 characters ~ 2 tokens
Issue reference
N/A – discovered during usage with large text inputs. Please let me know if you'd like me to open a tracking issue.
Checklist