j_r_r_token 1.2.1-arm-linux → 1.3.0-arm-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 52b66cba4ab2a4258bebb4fcb6870996c876e0c4754e6bc874aad96e0fc33719
4
- data.tar.gz: cbcaf5f22f1d731ef737c4d277193a410b0406e456d849db3aef7636e4f43483
3
+ metadata.gz: 58b9dfca705cd06a4530fb5cae0fe6acad2fd183167d09ecebf7bfdd0059bee2
4
+ data.tar.gz: 76178cffb643a7c90e2941964e273eb1d894e82d251e68d2246223cc6d890f4e
5
5
  SHA512:
6
- metadata.gz: a863b586337d828c8c4a323acfa18098a494c4f019a8b059b34347af90b3ceadae9c0299be447aff1b0d2af026f1e02509b5771a0c1d7e648ff793b8968e4fb8
7
- data.tar.gz: 19de55bd05d3167ec4e47a50b1268564db68d34c5fe131e0844f2d13b8d76d1d910eedc6de4e86d6f6bb9d327d18dfbe5c4f98590c5f675d22439f037d50d3c5
6
+ metadata.gz: b2349b86aa748e89695d3507a8ee97eb0b67c09795a156ebe153ca72ac0cfebb9f7a138f76eec6782c54c24e7a6a226ee9fb42eb44b0594ceda96e5c176623ee
7
+ data.tar.gz: 5e063c925092022e472dac73ee9a8a1df8d8487059ff8c304b99c783a7a95d3f91f9d51b62f24ed1f012bba5987e9c637b2801b11df2696edec03e86badab1ba
data/CHANGELOG.md CHANGED
@@ -7,6 +7,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ---
11
+ ## [1.3.0] - 2026-11-22
12
+ ### Breaking Change
13
+ - Model mapping now matches OpenAI's tiktoken 0.14.0 exactly (via `tiktoken-rs` 0.12.1). `tiktoken-rs` 0.11 carried its own extra `o4` / `o4-*` mappings that OpenAI's tiktoken never had (it only maps `o4-mini`); 0.12 dropped them, so bare `o4` and `o4-pro` (any `o4-*` other than `o4-mini*`) now raise `ArgumentError`, as do fine-tunes of them (e.g. `ft:o4`). Use `o4-mini` or pass `o200k_base` directly.
14
+
15
+ ### Fix
16
+ - A whitespace run of ~1M+ characters followed by text previously killed the process with an uncatchable `fatal` (a Rust panic). It now raises a regular `RuntimeError` ("Could not encode string: ..."), so apps counting untrusted input can rescue it.
17
+
18
+ ### Change
19
+ - Bumped `tiktoken-rs` from 0.11.0 to 0.12.1, which vendors OpenAI's tiktoken 0.14.0 core.
20
+ - Following OpenAI's tiktoken 0.14.0, any model name beginning with `gpt-5` now resolves to `o200k_base` (previously only `gpt-5`, `gpt-5-*` and `gpt-5.*`).
21
+ - Long repetitive input no longer hits a quadratic slowdown: upstream's large-piece BPE merge brings 200 KB of `"a"` from ~15 s to well under a second. Counts are unchanged (verified against 0.11.0 across all encodings).
22
+ - The allowed special-token set is now built once per encoding instead of on every call; repeat `gpt-oss` (`o200k_harmony`, ~1,100 special tokens) counts are now on par with the other encodings.
23
+ - Building from source (the generic gem or `rake compile`) now requires Rust 1.85 or newer. Precompiled platform gems are unaffected.
24
+ - Tokenizers are now built once per process and cached (via `tiktoken_rs::bpe_for_tokenizer`) instead of being rebuilt on every `count` call. Previously each call decoded the full vocabulary and compiled the tokenizer regexes, costing ~20–120 ms per call depending on the encoding; repeat calls are now sub-millisecond for short text. The first call for each encoding still pays the one-time build cost.
25
+ - Memory tradeoff: each encoding, once used, now stays resident for the life of the process. Approximate RSS per encoding: `o200k_base` ~45 MB, `o200k_harmony` ~47 MB, `cl100k_base` ~24 MB, `p50k_base` / `p50k_edit` / `r50k_base` ~10 MB each. Only encodings you actually call are loaded.
26
+ - Bumped `magnus` from 0.8.2 to 0.8.5 (patch fixes). Staying on the 0.8 series, the last to support Ruby 3.0.
27
+ - Migrated the extension off magnus's deprecated "old-api" (global `define_module` / `exception::*`) to the `&Ruby` handle API and dropped the `old-api` feature flag. No behavior change.
28
+ - Bumped `rb_sys` (gem and crate) from 0.9.128 to 0.9.130. It still pins `rake-compiler-dock` 1.12.0, so Ruby 3.0 platform gems are unaffected.
29
+ - README: documented the `RuntimeError` case, the one-time build cost and memory per encoding (with a boot-time warm-up tip for preforking servers), and the Rust >= 1.85 requirement for source builds.
30
+ - Gemspec description now lists `o200k_harmony`; added RBS signatures for `JRRToken::Tokenizer.count`.
31
+ - CI: the cross-gem matrix is now an explicit allowlist of the seven platforms this gem ships (`aarch64-linux`, `aarch64-linux-musl`, `arm-linux`, `arm64-darwin`, `x86_64-darwin`, `x86_64-linux`, `x86_64-linux-musl`) instead of an exclude list. The platform list comes from rb-sys `main` at release time, so new rb-sys targets (e.g. `arm-linux-musl`, added in 0.9.130) previously slipped into the release matrix; adding a platform is now a deliberate edit.
32
+ - CI: test jobs pin `ubuntu-24.04` instead of `ubuntu-latest`. Ruby 3.2.11's ubuntu-26.04 build (from ruby/ruby-builder, compiled with GCC 15 in C23 mode) lacks `HAVE_STDBOOL_H` in its `config.h`, so rb-sys's bindgen step fails with "unknown type name 'bool'". Other Ruby versions on that image, and Ruby 3.2 on the ARM Linux and macOS runners, were unaffected.
33
+
10
34
  ---
11
35
  ## [1.2.1] - 2026-05-13
12
36
  ### Breaking Change
data/README.md CHANGED
@@ -1,10 +1,17 @@
1
- # JRRToken [<img src="https://github.com/LoganBresnahan/j_r_r_token/raw/main/.github/assets/ring.png" width="32px" alt="One ring to rule them all, one ring to find them, One ring to bring them all and in the darkness bind them.">](https://www.youtube.com/watch?v=lemgdzLDYqA)
1
+ <p align="center">
2
+ <img src="https://github.com/LoganBresnahan/j_r_r_token/raw/main/.github/assets/rings.png" height="120px" alt="JRRToken" />
3
+ </p>
2
4
 
3
- (Just Ruby, Rust, & Tokens)
5
+ <h1 align="center">JRRToken</h1>
6
+ <h2 align="center">v1.3.0</h2>
7
+
8
+ <p align="center">(Just Ruby, Rust, &amp; Tokens)</p>
9
+
10
+ ---
4
11
 
5
12
  JRRToken provides a high-performance, native Ruby interface for counting tokens using the powerful [tiktoken-rs](https://github.com/zurawiki/tiktoken-rs) library. It leverages the speed of Rust to offer a fast and efficient way to calculate token counts for various OpenAI models.
6
13
 
7
- The gem ships with pre-compiled native extensions for Linux and macOS, so your end-users don't need a Rust toolchain installed.
14
+ The gem ships with pre-compiled native extensions for Linux and macOS, so your end-users don't need a Rust toolchain installed. On other platforms the gem builds from source, which requires Rust >= 1.85.
8
15
 
9
16
  Supports Ruby >= 3.0.0
10
17
 
@@ -15,10 +22,10 @@ Extensive Model Support: Includes tokenizers for all modern and legacy OpenAI mo
15
22
  ## Install
16
23
 
17
24
  #### Gemfile
18
- `gem 'j_r_r_token', '~> 1.2'`
25
+ `gem 'j_r_r_token', '~> 1.3'`
19
26
 
20
27
  #### Command Line
21
- `gem install j_r_r_token -v '~> 1.2'`
28
+ `gem install j_r_r_token -v '~> 1.3'`
22
29
 
23
30
  ## Use
24
31
 
@@ -37,7 +44,10 @@ count = JRRToken::Tokenizer.count("hello world!", model: "text-davinci-003")
37
44
  count = JRRToken::Tokenizer.count(1234, model: "o200k_base")
38
45
  ```
39
46
 
40
- If you provide an unsupported model name, the gem will raise an `ArgumentError`.
47
+ ### Errors
48
+ - An unsupported model name raises `ArgumentError`.
49
+ - A model that isn't a String (e.g. `nil` or a Symbol) raises `TypeError`.
50
+ - If the tokenizer itself fails on pathological input (for example, a whitespace run of roughly a million characters followed by text), the gem raises `RuntimeError`. When counting untrusted input, rescue it or cap the input size.
41
51
 
42
52
  ## Supported Models
43
53
  The gem automatically maps dozens of model names and prefixes to the correct underlying tokenizer. You don't need to know the tokenizer's base name (e.g., cl100k_base); just use the model name you're working with. Model resolution is delegated to [`tiktoken-rs`](https://github.com/zurawiki/tiktoken-rs), so the alias list stays in sync with upstream.
@@ -51,6 +61,18 @@ The gem automatically maps dozens of model names and prefixes to the correct und
51
61
 
52
62
  Fine-tuned models (`ft:<base>:org:name:id`) are automatically resolved to the same tokenizer as their base model.
53
63
 
64
+ ## Performance and Memory
65
+ Each tokenizer is built the first time you use it (roughly 15–85 ms, depending on the encoding) and then cached for the life of the process, so later calls are fast. A cached tokenizer stays in memory: roughly 45 MB for `o200k_base` and `o200k_harmony`, 24 MB for `cl100k_base`, and 10 MB each for the older encodings. Only the encodings you actually use are loaded.
66
+
67
+ To keep that one-time cost out of your first request, warm up the encodings you use at boot:
68
+
69
+ ```Ruby
70
+ # e.g. config/initializers/j_r_r_token.rb
71
+ JRRToken::Tokenizer.count("", model: "gpt-4o")
72
+ ```
73
+
74
+ With a preforking server (Puma with `preload_app!`, Unicorn with `preload_app true`), warming up before the fork lets the workers share the tokenizer memory copy-on-write instead of each building its own.
75
+
54
76
  ## Developing JRRToken Locally
55
77
 
56
78
  ### Install Ruby and Rust dependencies
@@ -58,7 +80,7 @@ Ruby >= 3.0.0
58
80
 
59
81
  RubyGems >= 3.0.0
60
82
 
61
- Rust edition 2021
83
+ Rust >= 1.85
62
84
 
63
85
  ### Compile the Rust extension and run tests
64
86
  Compile:
data/j_r_r_token.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ["loganbbres@gmail.com"]
10
10
 
11
11
  spec.summary = "Ruby wrapper for the tiktoken Rust library, providing fast tokenization for OpenAI models."
12
- spec.description = "JRRToken is a Ruby gem that wraps the tiktoken Rust library, enabling fast and efficient tokenization for OpenAI models. It supports multiple models including o200k_base, cl100k_base, p50k_base, p50k_edit, and r50k_base."
12
+ spec.description = "JRRToken is a Ruby gem that wraps the tiktoken Rust library, enabling fast and efficient tokenization for OpenAI models. It supports the o200k_harmony, o200k_base, cl100k_base, p50k_base, p50k_edit, and r50k_base encodings."
13
13
  spec.homepage = "https://github.com/LoganBresnahan/j_r_r_token"
14
14
  spec.license = "MIT"
15
15
  spec.required_ruby_version = ">= 3.0.0"
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JRRToken
4
- VERSION = "1.2.1"
4
+ VERSION = "1.3.0"
5
5
  end
data/sig/j_r_r_token.rbs CHANGED
@@ -1,4 +1,15 @@
1
1
  module JRRToken
2
2
  VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
3
+
4
+ # Native extension entry point (implemented in Rust).
5
+ def self.count_tokens: (String model, String text) -> Integer
6
+
7
+ class Error < StandardError
8
+ end
9
+
10
+ class Tokenizer
11
+ # Counts tokens in `text` (converted with #to_s) for the given model or encoding name.
12
+ # Raises ArgumentError for an unsupported model, RuntimeError if tokenization fails.
13
+ def self.count: (_ToS text, model: String) -> Integer
14
+ end
4
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: j_r_r_token
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: arm-linux
6
6
  authors:
7
7
  - Logan Bresnahan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-05-13 00:00:00.000000000 Z
11
+ date: 2026-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -53,8 +53,8 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: JRRToken is a Ruby gem that wraps the tiktoken Rust library, enabling
56
- fast and efficient tokenization for OpenAI models. It supports multiple models including
57
- o200k_base, cl100k_base, p50k_base, p50k_edit, and r50k_base.
56
+ fast and efficient tokenization for OpenAI models. It supports the o200k_harmony,
57
+ o200k_base, cl100k_base, p50k_base, p50k_edit, and r50k_base encodings.
58
58
  email:
59
59
  - loganbbres@gmail.com
60
60
  executables: []