Repository navigation
fix: count literal special-token strings instead of crashing - #13014
milangeorge2000 wants to merge 2 commits into
Conversation
TiktokenCounter.count() used Encoding.encode(), which raises ValueError on text containing special-token markers like <|endoftext|>. Since allowed_special is empty here, the strict check can never emit a special token - it only turns ordinary source text into a crash. Switch to encode_ordinary(), matching the deepset-ai#12853 fix for the document splitters. Adds a regression test and release note. Fixes deepset-ai#12869.
|
Someone is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
|
Hi @milangeorge2000, thanks for your interest in contributing to Haystack! 🙏 This is an automated message to help us keep the review queue healthy. |
|
milan varghese george seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
|
Hi @milangeorge2000, thanks a lot for your contribution! 🙏 We noticed that the Contributor License Agreement (CLA) check ( To get your PR reviewed, please sign the CLA via the link in the |
|
Thank you for your efforts! We're closing this PR because it duplicates #13009, which makes the same one-line fix to |
Haystack PR — Fixes #12869
TiktokenCounter.count()usedEncoding.encode(), which raisesValueErroron text containing special-token markers like<|endoftext|>. Sinceallowed_specialis empty at this call site, the strict check can never emit a special token — it only turns ordinary source text into a crash.Changes
encode_ordinary()instead ofencode(), matching the earlier#12853fix forDocumentSplitter/RecursiveDocumentSplitter._FakeEncodertest double (it now stubsencode_ordinary) and added a regression test with a literal<|endoftext|>marker.Verification (observed)
encode()raisesValueError: ... disallowed special token ...;encode_ordinary()returns 9 tokens for the same string.test/token_counters/: 45 passed, 1 skipped via Hatch.hatch run fmt: all checks passed.