tiktoken_ruby 0.0.16-arm-linux → 0.0.17-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: dcf37e12602d4fd40d0e772491ebd3381d1bdd6118ba11a4da0710c303315bcf
4
- data.tar.gz: 87fc8e242d5597f9f1aa60ea6b8b976377b208c3dbc7bc767d1a50780c48e7b4
3
+ metadata.gz: ebd4c57be399d89e76b2777068873199c52172948884a8db62a83df24ad8d272
4
+ data.tar.gz: b30cc6f157197e24eb1ccf65f42fbccc524e22bc2587e34cdc2a1e2de085f366
5
5
  SHA512:
6
- metadata.gz: a03f0c062e93f1ff3955d5466fa66721ca7dad6a319c764a1df7b3ab14efe29b31a075de68f9c64c52d49d74ce4dfd8ff09a758e6ccb0d3d4b2622e928077f40
7
- data.tar.gz: e36c0a9c9d0b78584131afe6755d7c2b5cd28eafc4e5561c4e2d35afc5b1a357cb227275b173894648c15752402505baeb1ed8e74af9dbeccce5a322e6bec7e9
6
+ metadata.gz: e4e528f55eeb58501416eaf5b000b9ef02bc64bd2607dff76639379fe96227a50b99af3749077a8c6e9c19933a2416bb81cdb6f2224a2498712b84e345f9646c
7
+ data.tar.gz: cefd97d8943197f5ca84c3469df4b99bc72716320057c9d3c392658c6315aed88260200fdb1f5fab808652871dccd6b6e096241d39d5c9790f970da6bfc0dd3c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ # [v0.0.17] - 18-07-2026
2
+ ## What's Changed
3
+ * Bump the github-actions group with 2 updates by @dependabot[bot] in https://github.com/IAPark/tiktoken_ruby/pull/119
4
+ * Bump the bundler-dependencies group across 1 directory with 2 updates by @dependabot[bot] in https://github.com/IAPark/tiktoken_ruby/pull/121
5
+ * Bump the cargo group across 1 directory with 2 updates by @dependabot[bot] in https://github.com/IAPark/tiktoken_ruby/pull/120
6
+ * feat(decode): Add opt-in lossy mode and decode_bytes by @gjtorikian in https://github.com/IAPark/tiktoken_ruby/pull/123
7
+ * Bump version to 0.0.17 by @gjtorikian in https://github.com/IAPark/tiktoken_ruby/pull/124
8
+
9
+
10
+ **Full Changelog**: https://github.com/IAPark/tiktoken_ruby/compare/v0.0.16...v0.0.17
1
11
  # [v0.0.16] - 02-05-2026
2
12
  ## What's Changed
3
13
  * Bump rb-sys from 0.9.123 to 0.9.124 in the cargo group by @dependabot[bot] in https://github.com/IAPark/tiktoken_ruby/pull/107
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tiktoken_ruby (0.0.16)
4
+ tiktoken_ruby (0.0.17)
5
5
  rb_sys (~> 0.9)
6
6
 
7
7
  GEM
@@ -9,13 +9,13 @@ GEM
9
9
  specs:
10
10
  ast (2.4.3)
11
11
  diff-lcs (1.6.2)
12
- json (2.18.1)
12
+ json (2.20.0)
13
13
  language_server-protocol (3.17.0.5)
14
14
  lint_roller (1.1.0)
15
15
  minitest (6.0.1)
16
16
  prism (~> 1.5)
17
- parallel (1.27.0)
18
- parser (3.3.10.2)
17
+ parallel (1.28.0)
18
+ parser (3.3.11.1)
19
19
  ast (~> 2.4.1)
20
20
  racc
21
21
  prism (1.9.0)
@@ -25,9 +25,9 @@ GEM
25
25
  rake-compiler (1.3.1)
26
26
  rake
27
27
  rake-compiler-dock (1.12.0)
28
- rb_sys (0.9.127)
28
+ rb_sys (0.9.128)
29
29
  rake-compiler-dock (= 1.12.0)
30
- regexp_parser (2.11.3)
30
+ regexp_parser (2.12.0)
31
31
  rspec (3.13.2)
32
32
  rspec-core (~> 3.13.0)
33
33
  rspec-expectations (~> 3.13.0)
@@ -41,18 +41,18 @@ GEM
41
41
  diff-lcs (>= 1.2.0, < 2.0)
42
42
  rspec-support (~> 3.13.0)
43
43
  rspec-support (3.13.6)
44
- rubocop (1.84.2)
44
+ rubocop (1.87.0)
45
45
  json (~> 2.3)
46
46
  language_server-protocol (~> 3.17.0.2)
47
47
  lint_roller (~> 1.1.0)
48
- parallel (~> 1.10)
48
+ parallel (>= 1.10)
49
49
  parser (>= 3.3.0.2)
50
50
  rainbow (>= 2.2.2, < 4.0)
51
51
  regexp_parser (>= 2.9.3, < 3.0)
52
52
  rubocop-ast (>= 1.49.0, < 2.0)
53
53
  ruby-progressbar (~> 1.7)
54
54
  unicode-display_width (>= 2.4.0, < 4.0)
55
- rubocop-ast (1.49.0)
55
+ rubocop-ast (1.49.1)
56
56
  parser (>= 3.3.7.2)
57
57
  prism (~> 1.7)
58
58
  rubocop-performance (1.26.1)
@@ -60,10 +60,10 @@ GEM
60
60
  rubocop (>= 1.75.0, < 2.0)
61
61
  rubocop-ast (>= 1.47.1, < 2.0)
62
62
  ruby-progressbar (1.13.0)
63
- standard (1.54.0)
63
+ standard (1.55.0)
64
64
  language_server-protocol (~> 3.17.0.2)
65
65
  lint_roller (~> 1.0)
66
- rubocop (~> 1.84.0)
66
+ rubocop (~> 1.87.0)
67
67
  standard-custom (~> 1.0.0)
68
68
  standard-performance (~> 1.8)
69
69
  standard-custom (1.0.2)
data/README.md CHANGED
@@ -17,9 +17,7 @@ If bundler is not being used to manage dependencies, install the gem by executin
17
17
 
18
18
  ## Usage
19
19
 
20
- Usage should be very similar to the python library. Here's a simple example
21
-
22
- Encode and decode text
20
+ Encode and decode text:
23
21
 
24
22
  ```ruby
25
23
  require 'tiktoken_ruby'
@@ -27,7 +25,7 @@ enc = Tiktoken.get_encoding("cl100k_base")
27
25
  enc.decode(enc.encode("hello world")) #=> "hello world"
28
26
  ```
29
27
 
30
- Encoders can also be retrieved by model name
28
+ Encoders can also be retrieved by model name:
31
29
 
32
30
  ```ruby
33
31
  require 'tiktoken_ruby'
@@ -69,6 +67,27 @@ enc.encode_with_special_tokens(text)
69
67
 
70
68
  All methods round-trip correctly through `decode`.
71
69
 
70
+ ### Decoding methods
71
+
72
+ - `decode(tokens, errors: :strict)` - Decodes tokens back into a UTF-8 string
73
+ - `decode_bytes(tokens)` - Decodes tokens into their raw bytes (an `ASCII-8BIT` string), without UTF-8 validation
74
+
75
+ Because BPE tokens are byte-level, a single character (an emoji, or non-Latin scripts) can span multiple tokens. Truncating a token array (like, "trim text to N tokens") can leave a prefix that is not valid UTF-8. The `errors:` option controls how those invalid sequences are handled.
76
+
77
+ ```ruby
78
+ enc = Tiktoken.encoding_for_model("gpt-4o")
79
+ tokens = enc.encode("🦄") # the emoji spans multiple tokens
80
+
81
+ # :strict (default) - raise Tiktoken::UnicodeError on invalid UTF-8
82
+ enc.decode(tokens.first(2)) #=> raises Tiktoken::UnicodeError
83
+
84
+ # :replace - substitute invalid sequences with "�" (matches Python tiktoken's default)
85
+ enc.decode(tokens.first(2), errors: :replace) #=> "�"
86
+
87
+ # decode_bytes - get the raw bytes and handle them yourself
88
+ enc.decode_bytes(tokens.first(2)) #=> "\xF0\x9F\xA6" (ASCII-8BIT)
89
+ ```
90
+
72
91
  ## Development
73
92
 
74
93
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
Binary file
Binary file
Binary file
Binary file
@@ -47,11 +47,41 @@ class Tiktoken::Encoding
47
47
  @ext_base_bpe.encode_with_special_tokens(text)
48
48
  end
49
49
 
50
- # Decodes the tokens back into text
50
+ # Decodes the tokens back into text.
51
+ #
52
+ # BPE tokens are byte-level, so a single character (an emoji, non-Latin
53
+ # scripts) can span multiple tokens. Truncating a token array to a limit can
54
+ # therefore leave a prefix that is not valid UTF-8. The +errors+ option
55
+ # controls how those invalid byte sequences are handled:
56
+ #
57
+ # * +:strict+ (default) - raise Tiktoken::UnicodeError on invalid UTF-8.
58
+ # * +:replace+ - substitute each invalid sequence with the Unicode replacement
59
+ # character (U+FFFD, +�+), matching Python tiktoken's default behavior.
60
+ #
51
61
  # @param tokens [Array<Integer>] The tokens to decode
52
- # @return [String] The decoded text
53
- def decode(tokens)
54
- @ext_base_bpe.decode(tokens)
62
+ # @param errors [Symbol] How to handle invalid UTF-8 (:strict or :replace)
63
+ # @return [String] The decoded text (UTF-8)
64
+ def decode(tokens, errors: :strict)
65
+ case errors
66
+ when :strict
67
+ @ext_base_bpe.decode(tokens)
68
+ when :replace
69
+ decode_bytes(tokens).force_encoding(Encoding::UTF_8).scrub("\u{FFFD}")
70
+ else
71
+ raise ArgumentError, "errors must be :strict or :replace, got #{errors.inspect}"
72
+ end
73
+ end
74
+
75
+ # Decodes the tokens back into their raw bytes, without any UTF-8 validation.
76
+ #
77
+ # The returned string has ASCII-8BIT (binary) encoding and is not guaranteed
78
+ # to be valid UTF-8 — useful when you want to handle invalid sequences
79
+ # yourself. Matches Python tiktoken's +decode_bytes+.
80
+ #
81
+ # @param tokens [Array<Integer>] The tokens to decode
82
+ # @return [String] The decoded bytes (ASCII-8BIT)
83
+ def decode_bytes(tokens)
84
+ @ext_base_bpe.decode_bytes(tokens)
55
85
  end
56
86
 
57
87
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tiktoken
4
- VERSION = "0.0.16"
4
+ VERSION = "0.0.17"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiktoken_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  platform: arm-linux
6
6
  authors:
7
7
  - IAPark
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-05-02 00:00:00.000000000 Z
11
+ date: 2026-07-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: An unofficial Ruby wrapper for Tiktoken, a BPE tokenizer written by and
14
14
  used by OpenAI. It can be used to count the number of tokens in text before sending