j_r_r_token 1.1.0-aarch64-linux → 1.3.0-aarch64-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: e17685f1d81b35ff10603ae68f4e7a4ce89ba210bf6fb9312e8b1bb5199efcb4
4
- data.tar.gz: 0fedd30ce5c3f0d86cbfdf7eb139b891e001a6b3de350762c5e850627d241d99
3
+ metadata.gz: 8a9afca043d105133da63a8b522c82554dfed9369071aa0c4e741bbaef2dc346
4
+ data.tar.gz: 89e06015d56fdebc53b2774d309bea013b655af826cac85a00bf1f4b713cc063
5
5
  SHA512:
6
- metadata.gz: 6c706bfb03fb9f4f0158df2ad54446c696069aff49681bfdb373d0c506a5789af73b62638040e4c345bb5df4214959c2c64a8e1928225f8099a332c60f9d7e8a
7
- data.tar.gz: 78e508b15d569fb772b9a6ee5de2e499840d9f3c50bf0d531c9d0a6fded5d65c517175011ada1b4295fa08076b63b7c1d917164e21228ff2d7aa3fd156e753b0
6
+ metadata.gz: 2db31f7faac66a8bddaf074ba0aeea20e5b81783020ada8c3d69329f70156db2bcde8b54239db2584bb5ffa7bf10318f06058b9581ff47bd849a96a829e9ec08
7
+ data.tar.gz: 619efe87421f6e568daf17573a0bfbb2ff4296045262329d813afb11f9f6d98ac5a52774fd82c921858acc0be2f8630f5a06ac1ae5cdcd5885c317a5b6e1685d
data/CHANGELOG.md CHANGED
@@ -7,6 +7,51 @@ 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
+
34
+ ---
35
+ ## [1.2.1] - 2026-05-13
36
+ ### Breaking Change
37
+ - Minimum Ruby version raised from 2.7.0 to 3.0.0. Ruby 2.7 has been EOL since March 2023 and is no longer supported by upstream `rake-compiler-dock` (1.11.0+) which `rb_sys` uses for cross-compiling native gems. Production environments on Ruby 3.0+ are unaffected.
38
+
39
+ ### New Functionality
40
+ - Added `o200k_harmony` tokenizer with support for `gpt-oss-20b` and `gpt-oss-120b`.
41
+ - Added support for additional model aliases now recognized by `tiktoken-rs` 0.11: `gpt-5-mini`, `gpt-5-nano`, `gpt-5.x` decimal variants (e.g. `gpt-5.4`, `gpt-5.4-pro`, `gpt-5.2-codex`), `gpt-4.5-*`, `o1`, `o3`, `o4-mini`, `codex-mini`, `codex-mini-latest`, and `ft:gpt-5` fine-tunes.
42
+ - Fine-tuned model resolution (`ft:` prefix) is now handled natively by the upstream `get_tokenizer` mapping, so any future ft: bases are picked up automatically.
43
+
44
+ ### Change
45
+ - Bumped `tiktoken-rs` from 0.7 to 0.11.
46
+ - Bumped `magnus` from 0.6 to 0.8 (with the `old-api` feature enabled to preserve current bindings). Still supports Ruby >= 3.0.
47
+ - Refactored Rust model dispatch to delegate to `tiktoken_rs::tokenizer::get_tokenizer` instead of maintaining a parallel alias list. The gem now stays in sync with upstream OpenAI tiktoken automatically on each `tiktoken-rs` bump.
48
+ - CI matrix trimmed: dropped deprecated `macos-13`; consolidated to `ubuntu-latest`, `ubuntu-24.04-arm`, `macos-latest`, `macos-15-intel`. Added Ruby 4.0 to both test and cross-gem builds.
49
+
50
+ ---
51
+ ## [1.2.0] - 2026-05-13
52
+ ### Note
53
+ - Partial release. The `arm-linux` cross-compile leg failed because upstream `rake-compiler-dock` 1.11.0+ dropped Ruby 2.7, so the published artifact set is incomplete. Please use 1.2.1 instead, which drops Ruby 2.7 from the support matrix and ships a complete set of platform gems.
54
+
10
55
  ---
11
56
  ## [1.1.0] - 2025-08-26
12
57
  ### New Functionality
data/README.md CHANGED
@@ -1,12 +1,19 @@
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
- Supports Ruby >= 2.7.0
16
+ Supports Ruby >= 3.0.0
10
17
 
11
18
  Extensive Model Support: Includes tokenizers for all modern and legacy OpenAI models, recognizing dozens of model aliases automatically.
12
19
 
@@ -15,16 +22,16 @@ 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.1'`
25
+ `gem 'j_r_r_token', '~> 1.3'`
19
26
 
20
27
  #### Command Line
21
- `gem install j_r_r_token -v '~> 1.1'`
28
+ `gem install j_r_r_token -v '~> 1.3'`
22
29
 
23
30
  ## Use
24
31
 
25
32
  ### Count tokens for a specific model (the model keyword is required)
26
33
  ```Ruby
27
- count = JRRToken::Tokenizer.count("hello world!", model: "gpt-5")
34
+ count = JRRToken::Tokenizer.count("hello world!", model: "gpt-5.4")
28
35
  ```
29
36
 
30
37
  ### The gem recognizes many aliases, including older models
@@ -37,25 +44,43 @@ 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
- 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.
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.
44
54
 
45
- - o200k_base Models (e.g., gpt-5, gpt-4.1, gpt-4o)
46
- - cl100k_base Models (e.g., gpt-4, gpt-3.5)
55
+ - o200k_harmony Models (e.g., gpt-oss-20b, gpt-oss-120b)
56
+ - o200k_base Models (e.g., gpt-5.4, gpt-5-mini, gpt-4.5, gpt-4.1, gpt-4o, o1, o3, o4-mini, codex-mini)
57
+ - cl100k_base Models (e.g., gpt-4, gpt-3.5-turbo, text-embedding-3-small)
47
58
  - p50k_base Models (e.g., text-davinci-003)
48
59
  - r50k_base Models (e.g., gpt-2)
49
60
  - p50k_edit Models
50
61
 
62
+ Fine-tuned models (`ft:<base>:org:name:id`) are automatically resolved to the same tokenizer as their base model.
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
+
51
76
  ## Developing JRRToken Locally
52
77
 
53
78
  ### Install Ruby and Rust dependencies
54
- Ruby >= 2.7.0
79
+ Ruby >= 3.0.0
55
80
 
56
81
  RubyGems >= 3.0.0
57
82
 
58
- Rust edition 2021
83
+ Rust >= 1.85
59
84
 
60
85
  ### Compile the Rust extension and run tests
61
86
  Compile:
data/j_r_r_token.gemspec CHANGED
@@ -9,10 +9,10 @@ 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
- spec.required_ruby_version = ">= 2.7.0"
15
+ spec.required_ruby_version = ">= 3.0.0"
16
16
  spec.required_rubygems_version = ">= 3.0.0"
17
17
 
18
18
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
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.1.0"
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.1.0
4
+ version: 1.3.0
5
5
  platform: aarch64-linux
6
6
  authors:
7
7
  - Logan Bresnahan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-08-27 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: []
@@ -66,12 +66,12 @@ files:
66
66
  - README.md
67
67
  - j_r_r_token.gemspec
68
68
  - lib/j_r_r_token.rb
69
- - lib/j_r_r_token/2.7/j_r_r_token.so
70
69
  - lib/j_r_r_token/3.0/j_r_r_token.so
71
70
  - lib/j_r_r_token/3.1/j_r_r_token.so
72
71
  - lib/j_r_r_token/3.2/j_r_r_token.so
73
72
  - lib/j_r_r_token/3.3/j_r_r_token.so
74
73
  - lib/j_r_r_token/3.4/j_r_r_token.so
74
+ - lib/j_r_r_token/4.0/j_r_r_token.so
75
75
  - lib/j_r_r_token/version.rb
76
76
  - sig/j_r_r_token.rbs
77
77
  homepage: https://github.com/LoganBresnahan/j_r_r_token
@@ -90,10 +90,10 @@ required_ruby_version: !ruby/object:Gem::Requirement
90
90
  requirements:
91
91
  - - ">="
92
92
  - !ruby/object:Gem::Version
93
- version: '2.7'
93
+ version: '3.0'
94
94
  - - "<"
95
95
  - !ruby/object:Gem::Version
96
- version: 3.5.dev
96
+ version: 4.1.dev
97
97
  required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  requirements:
99
99
  - - ">="