j_r_r_token 1.0.0-arm64-darwin

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ceb33d317de17949aebb422787424e688042bb329d7d79234a47839419863d11
4
+ data.tar.gz: 4e83c6357d57fa09ff04187bd942649692e5d14316cfbea346139cae952b5b27
5
+ SHA512:
6
+ metadata.gz: b8f2edcc0c534704248e58cd83606756dfbc9e4a92d1ff61f115e2ba770fe251e90e4b45bb7dcb9dfb6476b9494e0ea60596ed2387a723f0be08ed3a5a722c0b
7
+ data.tar.gz: 38136e2d54699ba0b8f4e16adc78684cd54809b8e13062226b5914464a6e08903c5494a93c0e2dcd9f50cda12b6e943b464197bda110546d28788b52b21bcef2
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,140 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ---
11
+ ## [1.0.0] - 2025-08-01
12
+ ### Breaking Change
13
+ - Rename Gem from ru_token (RuToken) to j_r_r_token (JRRToken).
14
+ - The ru_token gem will be patched with a deprecation notice.
15
+ - Bumping the version to 1.0.0 to symbolize the gem is now in a stable state.
16
+
17
+ ---
18
+ ## [0.1.20] - 2025-07-31
19
+ ### Change
20
+ - Remove x64-mingw32 from Gemfile.lock
21
+ - Update README
22
+
23
+ ---
24
+ ## [0.1.19] - 2025-07-31
25
+ ### No Change
26
+ - Bumping to retry RubyGems deploy
27
+
28
+ ---
29
+ ## [0.1.18] - 2025-07-31
30
+ ### Change
31
+ - Update README
32
+
33
+ ---
34
+ ## [0.1.17] - 2025-07-31
35
+ ### Change
36
+ - Update gemspec license entry
37
+ - Remove platform x64-mingw-ucrt from Gemfile.lock
38
+
39
+ ---
40
+ ## [0.1.16] - 2025-07-31
41
+ ### Change
42
+ - Update license to MIT
43
+
44
+ ---
45
+ ## [0.1.15] - 2025-07-31
46
+ ### Fix
47
+ - Stable ruby version build syntax
48
+ - Add ruby versions manual list for build
49
+
50
+ ---
51
+ ## [0.1.14] - 2025-07-31
52
+ ### Fix
53
+ - Stable ruby version build syntax
54
+
55
+ ---
56
+ ## [0.1.13] - 2025-07-31
57
+ ### Fix
58
+ - Stable ruby version build syntax
59
+
60
+ ---
61
+ ## [0.1.12] - 2025-07-31
62
+ ### Fix
63
+ - Set stable ruby versions manually.
64
+ - Test macos-14 and macos-15
65
+
66
+ ---
67
+ ## [0.1.11] - 2025-07-31
68
+ ### Fix
69
+ - Set stable ruby versions to default in build.
70
+
71
+ ---
72
+ ## [0.1.10] - 2025-07-31
73
+ ### Fix
74
+ - Add stable ruby versions to ci data step in build.
75
+
76
+ ---
77
+ ## [0.1.9] - 2025-07-31
78
+ ### Fix
79
+ - Add required ruby version to build and deploy.
80
+
81
+ ---
82
+ ## [0.1.8] - 2025-07-30
83
+ ### Fix
84
+ - Correct loading paths for native gem versions.
85
+
86
+ ---
87
+ ## [0.1.7] - 2025-07-30
88
+ ### Changed
89
+ - Add Generic Gem Build.
90
+
91
+ ---
92
+ ## [0.1.6] - 2025-07-30
93
+ ### Changed
94
+ - Change build process to rely on Oxidize.
95
+
96
+ ---
97
+ ## [0.1.5] - 2025-07-30
98
+ ### Changed
99
+ - Update Deploy Process for PKG gem names.
100
+
101
+ ---
102
+ ## [0.1.4] - 2025-07-30
103
+ ### Changed
104
+ - Removed test runners from release process.
105
+
106
+ ---
107
+ ## [0.1.3] - 2025-07-30
108
+ ### Changed
109
+ - Update release process to properly pre-compile native gems.
110
+
111
+ ---
112
+ ## [0.1.2] - 2025-07-30
113
+
114
+ ### Changed
115
+ - Revamped the Linux publishing workflow to use the `oxidize-rb/actions/cross-gem` action. This produces highly portable "fat" gems for Linux, resulting in several key improvements:
116
+ - Pre-compiled gems are now provided for both `glibc` (standard Linux) and `musl` (Alpine Linux) systems.
117
+ - Both Intel (`x86_64`) and ARM (`aarch64`) architectures are now supported for both `glibc` and `musl`.
118
+ - Linux gems are now compatible with a much wider range of distributions, including older enterprise versions.
119
+
120
+ ---
121
+ ## [0.1.1] - 2025-07-30
122
+
123
+ ### Added
124
+ - Comprehensive RSpec test suite to validate token counts across all supported models.
125
+ - GitHub Actions workflow for continuous integration to automatically test against multiple Ruby versions and operating systems.
126
+ - Standard `rake release` task for simplified and automated gem publishing.
127
+
128
+ ### Changed
129
+ - Updated README with accurate usage examples and a complete, collapsible list of supported model aliases.
130
+ - Improved the default `rake` task to automatically compile the extension and run tests.
131
+
132
+ ### Fixed
133
+ - Corrected expected token counts in tests to match the `tiktoken-rs` library's actual output.
134
+
135
+ ---
136
+ ## [0.1.0] - 2025-07-29
137
+
138
+ ### Added
139
+ - Initial release of the `RuToken` gem.
140
+ - Core functionality to count tokens for OpenAI models using a native Rust extension.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Logan Bresnahan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # JRRToken [<img src="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://youtu.be/lemgdzLDYqA?si=Z_Ls3hbJ-Xv38oJN)
2
+
3
+ (Just Ruby Rust Tokens)
4
+
5
+ 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
+
7
+ The gem ships with pre-compiled native extensions for Linux and macOS, so your end-users don't need a Rust toolchain installed.
8
+
9
+ Supports Ruby >= 2.7.0
10
+
11
+ Extensive Model Support: Includes tokenizers for all modern and legacy OpenAI models, recognizing dozens of model aliases automatically.
12
+
13
+ [https://rubygems.org/gems/j_r_r_token](https://rubygems.org/gems/j_r_r_token)
14
+
15
+ ## Install
16
+
17
+ #### Gemfile
18
+ `gem 'j_r_r_token', '~> 1.0.0'`
19
+
20
+ #### Command Line
21
+ `gem install j_r_r_token -v '~> 1.0.0'`
22
+
23
+ ## Use
24
+
25
+ ### Count tokens for a specific model (the model keyword is required)
26
+ ```Ruby
27
+ count = JRRToken::Tokenizer.count("hello world!", model: "gpt-4.1")
28
+ ```
29
+
30
+ ### The gem recognizes many aliases, including older models
31
+ ```Ruby
32
+ count = JRRToken::Tokenizer.count("hello world!", model: "text-davinci-003")
33
+ ```
34
+
35
+ ### The count method calls .to_s on the argument if it is not a string
36
+ ```Ruby
37
+ count = JRRToken::Tokenizer.count(1234, model: "o200k_base")
38
+ ```
39
+
40
+ If you provide an unsupported model name, the gem will raise an `ArgumentError`.
41
+
42
+ ## 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.
44
+
45
+ - o200k_base Models (e.g., GPT-4o)
46
+ - cl100k_base Models (e.g., GPT-4, GPT-3.5)
47
+ - p50k_base Models (e.g., text-davinci-003)
48
+ - r50k_base Models (e.g., GPT-2)
49
+ - p50k_edit Models
50
+
51
+ ## Developing JRRToken Locally
52
+
53
+ ### Install Ruby and Rust dependencies
54
+ Ruby >= 2.7.0
55
+
56
+ RubyGems >= 3.0.0
57
+
58
+ Rust edition 2021
59
+
60
+ ### Compile the Rust extension and run tests
61
+ Compile:
62
+ `bundle exec rake compile`
63
+
64
+ Specs:
65
+ `bundle exec rake spec`
66
+
67
+ Both:
68
+ `bundle exec rake`
69
+
70
+ Interactive console for experimentation: `bin/console`
71
+
72
+ ## Contributing
73
+
74
+ Bug reports and pull requests are welcome on GitHub at https://github.com/LoganBresnahan/j_r_r_token.
75
+
76
+ ## License
77
+
78
+ The gem is available as open source under the terms of the MIT License.
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/extensiontask"
5
+ require "rb_sys/extensiontask"
6
+
7
+ GEMSPEC = Gem::Specification.load("j_r_r_token.gemspec")
8
+
9
+ RbSys::ExtensionTask.new("j_r_r_token", GEMSPEC) do |ext|
10
+ ext.lib_dir = "lib/j_r_r_token"
11
+ end
12
+
13
+ # Only require rspec if it's available
14
+ begin
15
+ require "rspec/core/rake_task"
16
+ RSpec::Core::RakeTask.new(:spec)
17
+ task default: %i[compile spec]
18
+ rescue LoadError
19
+ puts "RSpec not available"
20
+ task default: :compile
21
+ end
22
+
23
+ task :native, [:platform] do |_t, platform:|
24
+ sh "bundle", "exec", "rb-sys-dock", "--platform", platform, "--build"
25
+ end
26
+
27
+ task build: :compile
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/j_r_r_token/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "j_r_r_token"
7
+ spec.version = JRRToken::VERSION
8
+ spec.authors = ["Logan Bresnahan"]
9
+ spec.email = ["loganbbres@gmail.com"]
10
+
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."
13
+ spec.homepage = "https://github.com/LoganBresnahan/j_r_r_token"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.7.0"
16
+ spec.required_rubygems_version = ">= 3.0.0"
17
+
18
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = spec.homepage
21
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/CHANGELOG.md"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (File.expand_path(f) == __FILE__) ||
28
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
29
+ end
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+ spec.extensions = ["ext/j_r_r_token/Cargo.toml"]
35
+
36
+ # Development dependencies are managed here for the gem.
37
+ spec.add_development_dependency "bundler", ">= 2.0"
38
+ spec.add_development_dependency "rake", "~> 13.0"
39
+ spec.add_development_dependency "rake-compiler"
40
+
41
+ # For more information and examples about making a new gem, check out our
42
+ # guide at: https://bundler.io/guides/creating_gem.html
43
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JRRToken
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "j_r_r_token/version"
4
+
5
+ begin
6
+ ruby_version = RUBY_VERSION.split('.')[0..1].join('.')
7
+ require "j_r_r_token/#{ruby_version}/j_r_r_token"
8
+ rescue LoadError
9
+ begin
10
+ require "j_r_r_token/j_r_r_token"
11
+ rescue LoadError
12
+ warn "Failed to load j_r_r_token native extension."
13
+ end
14
+ end
15
+
16
+ module JRRToken
17
+ class Error < StandardError; end
18
+
19
+ # This is the main public interface for the gem.
20
+ class Tokenizer
21
+ # Counts tokens for a given text using a specified model name.
22
+ # The underlying Rust extension will handle mapping the model name
23
+ # to the correct tokenizer.
24
+ #
25
+ # @param text [String] The text to tokenize.
26
+ # @param model [String] The name of the model (e.g., "gpt-4o", "gpt-3.5-turbo").
27
+ # @return [Integer] The number of tokens.
28
+ def self.count(text, model:)
29
+ # This calls the `count_tokens` function from our Rust code,
30
+ # passing both the model and the text.
31
+ JRRToken.count_tokens(model, text.to_s)
32
+ end
33
+ end
34
+ end
data/ring.png ADDED
Binary file
@@ -0,0 +1,4 @@
1
+ module JRRToken
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: j_r_r_token
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: arm64-darwin
6
+ authors:
7
+ - Logan Bresnahan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-08-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake-compiler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
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.
58
+ email:
59
+ - loganbbres@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".rspec"
65
+ - CHANGELOG.md
66
+ - LICENSE
67
+ - README.md
68
+ - Rakefile
69
+ - j_r_r_token.gemspec
70
+ - lib/j_r_r_token.rb
71
+ - lib/j_r_r_token/2.7/j_r_r_token.bundle
72
+ - lib/j_r_r_token/3.0/j_r_r_token.bundle
73
+ - lib/j_r_r_token/3.1/j_r_r_token.bundle
74
+ - lib/j_r_r_token/3.2/j_r_r_token.bundle
75
+ - lib/j_r_r_token/3.3/j_r_r_token.bundle
76
+ - lib/j_r_r_token/3.4/j_r_r_token.bundle
77
+ - lib/j_r_r_token/version.rb
78
+ - ring.png
79
+ - sig/j_r_r_token.rbs
80
+ homepage: https://github.com/LoganBresnahan/j_r_r_token
81
+ licenses:
82
+ - MIT
83
+ metadata:
84
+ allowed_push_host: https://rubygems.org
85
+ homepage_uri: https://github.com/LoganBresnahan/j_r_r_token
86
+ source_code_uri: https://github.com/LoganBresnahan/j_r_r_token
87
+ changelog_uri: https://github.com/LoganBresnahan/j_r_r_token/blob/main/CHANGELOG.md
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '2.7'
97
+ - - "<"
98
+ - !ruby/object:Gem::Version
99
+ version: 3.5.dev
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: 3.0.0
105
+ requirements: []
106
+ rubygems_version: 3.5.23
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Ruby wrapper for the tiktoken Rust library, providing fast tokenization for
110
+ OpenAI models.
111
+ test_files: []