feat(review): pluggable per-model tokenizer for exact token counts
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- java
- Domain
- ai, backend-api-design
Research direction
Start by reading the implementation of the TokenCounter interface and the per-model configuration introduced by issues #53 and #50. Then inspect langchain4j's built-in estimators for OpenAI, Anthropic, and Gemini and how the budgeter uses them. Done means matching models use their provider estimator, unmatched models fall back to jtokkit, and self-calibration from API token usage continues.
Written by the indexing model from the issue text.
Description
Problem
The large-diff token budgeting (#53) ships with a single jtokkit (OpenAI BPE) encoding as the estimate for all providers, self-calibrated from the usage.prompt_tokens the API echoes back. That's exact for OpenAI models but approximate for others (e.g. DeepSeek/Gemini/Anthropic use different vocabularies). For closer budgeting on non-OpenAI models, make the estimator pluggable.
Proposed (enhancement — jtokkit stays the default)
- Keep the
TokenCounterinterface introduced by #53; the default stays jtokkit (OpenAI BPE) for any model without a better estimator. - Reuse langchain4j's built-in per-provider token estimators rather than rolling our own — langchain4j already ships estimators for OpenAI, Anthropic, and Gemini. Wire the matching one behind
TokenCounter, keyed by the configured model/provider, for better estimates on those specific models. - Fall back to jtokkit when no provider estimator matches; the budgeter keeps self-calibrating from
usage.prompt_tokensregardless, so estimates only improve.
No conflict with #53
This plugs in behind the same TokenCounter interface #53 introduces — #53 ships jtokkit-default; #239 swaps in the langchain4j per-provider estimator per model. Nothing in #53 changes.
Depends on
#53 — introduces TokenCounter + the jtokkit default + the per-model config surface (#50). Post-v0.3.0 enhancement.
- Dominant language
- Java
- Stars
- 35
- Forks
- 7
- Avg merge
- 9h 23m
- Merged PRs (30d)
- 154
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from devops-thiago/ThrillhouseBot
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
devops-thiago/ThrillhouseBot#1093 ·
Maintainers usually reply within 1 day
-
documentation enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
devops-thiago/ThrillhouseBot#321 ·
Maintainers usually reply within 1 day
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
devops-thiago/ThrillhouseBot#46 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 58/100
devops-thiago/ThrillhouseBot#1095 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 58/100
devops-thiago/ThrillhouseBot#1094 ·
Maintainers usually reply within 1 day
All issues in devops-thiago/ThrillhouseBot
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
GantMan/jail-monkey#380 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
objectionary/jucs#145 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
objectionary/lints#1559 ·
Maintainers usually reply within 2 days
-
RRateLimiter acquire methods accept negative permits and raise available permits above the rate.Possibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 4 days