tiktoken_ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 81166d50bf3f152dd63a68d0d40f364b8232c906d8e4534f6c47360ea72f99a7
4
+ data.tar.gz: 93b7db86bfd25bc04dffd1c7568b95ac7421c0445865c86776a4a6b58248fbd5
5
+ SHA512:
6
+ metadata.gz: '03950362233a94958d1811f183e5151d4f52d38b11c913810e819bba78728d9c89b0cf49489346b19a3d735cf67efa2e4718a34cea9d3e65166e333d115c2536'
7
+ data.tar.gz: 9ee22a55ee71ec3e75fa6090984faa1f9b565532331fa91e6295ab0760264f75d94aee1688e59bc2191aeac8e90423a2ac48d73dfa3e7c833966532adae67788
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/testdouble/standard
3
+ ruby_version: 2.6
data/Cargo.lock ADDED
@@ -0,0 +1,484 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 3
4
+
5
+ [[package]]
6
+ name = "aho-corasick"
7
+ version = "0.7.20"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac"
10
+ dependencies = [
11
+ "memchr",
12
+ ]
13
+
14
+ [[package]]
15
+ name = "anyhow"
16
+ version = "1.0.70"
17
+ source = "registry+https://github.com/rust-lang/crates.io-index"
18
+ checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4"
19
+
20
+ [[package]]
21
+ name = "autocfg"
22
+ version = "1.1.0"
23
+ source = "registry+https://github.com/rust-lang/crates.io-index"
24
+ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
25
+
26
+ [[package]]
27
+ name = "base64"
28
+ version = "0.21.0"
29
+ source = "registry+https://github.com/rust-lang/crates.io-index"
30
+ checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a"
31
+
32
+ [[package]]
33
+ name = "bindgen"
34
+ version = "0.60.1"
35
+ source = "registry+https://github.com/rust-lang/crates.io-index"
36
+ checksum = "062dddbc1ba4aca46de6338e2bf87771414c335f7b2f2036e8f3e9befebf88e6"
37
+ dependencies = [
38
+ "bitflags",
39
+ "cexpr",
40
+ "clang-sys",
41
+ "lazy_static",
42
+ "lazycell",
43
+ "peeking_take_while",
44
+ "proc-macro2",
45
+ "quote",
46
+ "regex",
47
+ "rustc-hash",
48
+ "shlex",
49
+ ]
50
+
51
+ [[package]]
52
+ name = "bit-set"
53
+ version = "0.5.3"
54
+ source = "registry+https://github.com/rust-lang/crates.io-index"
55
+ checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1"
56
+ dependencies = [
57
+ "bit-vec",
58
+ ]
59
+
60
+ [[package]]
61
+ name = "bit-vec"
62
+ version = "0.6.3"
63
+ source = "registry+https://github.com/rust-lang/crates.io-index"
64
+ checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb"
65
+
66
+ [[package]]
67
+ name = "bitflags"
68
+ version = "1.3.2"
69
+ source = "registry+https://github.com/rust-lang/crates.io-index"
70
+ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
71
+
72
+ [[package]]
73
+ name = "bstr"
74
+ version = "1.4.0"
75
+ source = "registry+https://github.com/rust-lang/crates.io-index"
76
+ checksum = "c3d4260bcc2e8fc9df1eac4919a720effeb63a3f0952f5bf4944adfa18897f09"
77
+ dependencies = [
78
+ "memchr",
79
+ "once_cell",
80
+ "regex-automata",
81
+ "serde",
82
+ ]
83
+
84
+ [[package]]
85
+ name = "cexpr"
86
+ version = "0.6.0"
87
+ source = "registry+https://github.com/rust-lang/crates.io-index"
88
+ checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
89
+ dependencies = [
90
+ "nom",
91
+ ]
92
+
93
+ [[package]]
94
+ name = "cfg-if"
95
+ version = "1.0.0"
96
+ source = "registry+https://github.com/rust-lang/crates.io-index"
97
+ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
98
+
99
+ [[package]]
100
+ name = "clang-sys"
101
+ version = "1.6.0"
102
+ source = "registry+https://github.com/rust-lang/crates.io-index"
103
+ checksum = "77ed9a53e5d4d9c573ae844bfac6872b159cb1d1585a83b29e7a64b7eef7332a"
104
+ dependencies = [
105
+ "glob",
106
+ "libc",
107
+ "libloading",
108
+ ]
109
+
110
+ [[package]]
111
+ name = "fancy-regex"
112
+ version = "0.11.0"
113
+ source = "registry+https://github.com/rust-lang/crates.io-index"
114
+ checksum = "b95f7c0680e4142284cf8b22c14a476e87d61b004a3a0861872b32ef7ead40a2"
115
+ dependencies = [
116
+ "bit-set",
117
+ "regex",
118
+ ]
119
+
120
+ [[package]]
121
+ name = "glob"
122
+ version = "0.3.1"
123
+ source = "registry+https://github.com/rust-lang/crates.io-index"
124
+ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
125
+
126
+ [[package]]
127
+ name = "lazy_static"
128
+ version = "1.4.0"
129
+ source = "registry+https://github.com/rust-lang/crates.io-index"
130
+ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
131
+
132
+ [[package]]
133
+ name = "lazycell"
134
+ version = "1.3.0"
135
+ source = "registry+https://github.com/rust-lang/crates.io-index"
136
+ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
137
+
138
+ [[package]]
139
+ name = "libc"
140
+ version = "0.2.140"
141
+ source = "registry+https://github.com/rust-lang/crates.io-index"
142
+ checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c"
143
+
144
+ [[package]]
145
+ name = "libloading"
146
+ version = "0.7.4"
147
+ source = "registry+https://github.com/rust-lang/crates.io-index"
148
+ checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f"
149
+ dependencies = [
150
+ "cfg-if",
151
+ "winapi",
152
+ ]
153
+
154
+ [[package]]
155
+ name = "lock_api"
156
+ version = "0.4.9"
157
+ source = "registry+https://github.com/rust-lang/crates.io-index"
158
+ checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df"
159
+ dependencies = [
160
+ "autocfg",
161
+ "scopeguard",
162
+ ]
163
+
164
+ [[package]]
165
+ name = "magnus"
166
+ version = "0.4.4"
167
+ source = "registry+https://github.com/rust-lang/crates.io-index"
168
+ checksum = "fc87660cd7daa49fddbfd524c836de54d5c927d520cd163f43700c5087c57d6c"
169
+ dependencies = [
170
+ "magnus-macros",
171
+ "rb-sys",
172
+ "rb-sys-env",
173
+ ]
174
+
175
+ [[package]]
176
+ name = "magnus-macros"
177
+ version = "0.3.0"
178
+ source = "registry+https://github.com/rust-lang/crates.io-index"
179
+ checksum = "206cb23bfeea05180c97522ef6a3e52a4eb17b0ed2f30ee3ca9c4f994d2378ae"
180
+ dependencies = [
181
+ "proc-macro2",
182
+ "quote",
183
+ "syn",
184
+ ]
185
+
186
+ [[package]]
187
+ name = "memchr"
188
+ version = "2.5.0"
189
+ source = "registry+https://github.com/rust-lang/crates.io-index"
190
+ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
191
+
192
+ [[package]]
193
+ name = "minimal-lexical"
194
+ version = "0.2.1"
195
+ source = "registry+https://github.com/rust-lang/crates.io-index"
196
+ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
197
+
198
+ [[package]]
199
+ name = "nom"
200
+ version = "7.1.3"
201
+ source = "registry+https://github.com/rust-lang/crates.io-index"
202
+ checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
203
+ dependencies = [
204
+ "memchr",
205
+ "minimal-lexical",
206
+ ]
207
+
208
+ [[package]]
209
+ name = "once_cell"
210
+ version = "1.17.1"
211
+ source = "registry+https://github.com/rust-lang/crates.io-index"
212
+ checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
213
+
214
+ [[package]]
215
+ name = "parking_lot"
216
+ version = "0.12.1"
217
+ source = "registry+https://github.com/rust-lang/crates.io-index"
218
+ checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
219
+ dependencies = [
220
+ "lock_api",
221
+ "parking_lot_core",
222
+ ]
223
+
224
+ [[package]]
225
+ name = "parking_lot_core"
226
+ version = "0.9.7"
227
+ source = "registry+https://github.com/rust-lang/crates.io-index"
228
+ checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521"
229
+ dependencies = [
230
+ "cfg-if",
231
+ "libc",
232
+ "redox_syscall",
233
+ "smallvec",
234
+ "windows-sys",
235
+ ]
236
+
237
+ [[package]]
238
+ name = "peeking_take_while"
239
+ version = "0.1.2"
240
+ source = "registry+https://github.com/rust-lang/crates.io-index"
241
+ checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
242
+
243
+ [[package]]
244
+ name = "proc-macro2"
245
+ version = "1.0.52"
246
+ source = "registry+https://github.com/rust-lang/crates.io-index"
247
+ checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224"
248
+ dependencies = [
249
+ "unicode-ident",
250
+ ]
251
+
252
+ [[package]]
253
+ name = "quote"
254
+ version = "1.0.26"
255
+ source = "registry+https://github.com/rust-lang/crates.io-index"
256
+ checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc"
257
+ dependencies = [
258
+ "proc-macro2",
259
+ ]
260
+
261
+ [[package]]
262
+ name = "rb-sys"
263
+ version = "0.9.68"
264
+ source = "registry+https://github.com/rust-lang/crates.io-index"
265
+ checksum = "4783528e031c3902524cfe685e0008d644e8b34bad4d1a19c1f39f4394d0777b"
266
+ dependencies = [
267
+ "rb-sys-build",
268
+ ]
269
+
270
+ [[package]]
271
+ name = "rb-sys-build"
272
+ version = "0.9.68"
273
+ source = "registry+https://github.com/rust-lang/crates.io-index"
274
+ checksum = "14c04474335dd597126d20fe90d94504b3582a30cbc36bc72c7d6ed3ef8cf168"
275
+ dependencies = [
276
+ "bindgen",
277
+ "lazy_static",
278
+ "proc-macro2",
279
+ "quote",
280
+ "regex",
281
+ "shell-words",
282
+ "syn",
283
+ ]
284
+
285
+ [[package]]
286
+ name = "rb-sys-env"
287
+ version = "0.1.2"
288
+ source = "registry+https://github.com/rust-lang/crates.io-index"
289
+ checksum = "a35802679f07360454b418a5d1735c89716bde01d35b1560fc953c1415a0b3bb"
290
+
291
+ [[package]]
292
+ name = "redox_syscall"
293
+ version = "0.2.16"
294
+ source = "registry+https://github.com/rust-lang/crates.io-index"
295
+ checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
296
+ dependencies = [
297
+ "bitflags",
298
+ ]
299
+
300
+ [[package]]
301
+ name = "regex"
302
+ version = "1.7.1"
303
+ source = "registry+https://github.com/rust-lang/crates.io-index"
304
+ checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733"
305
+ dependencies = [
306
+ "aho-corasick",
307
+ "memchr",
308
+ "regex-syntax",
309
+ ]
310
+
311
+ [[package]]
312
+ name = "regex-automata"
313
+ version = "0.1.10"
314
+ source = "registry+https://github.com/rust-lang/crates.io-index"
315
+ checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
316
+
317
+ [[package]]
318
+ name = "regex-syntax"
319
+ version = "0.6.28"
320
+ source = "registry+https://github.com/rust-lang/crates.io-index"
321
+ checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848"
322
+
323
+ [[package]]
324
+ name = "rustc-hash"
325
+ version = "1.1.0"
326
+ source = "registry+https://github.com/rust-lang/crates.io-index"
327
+ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
328
+
329
+ [[package]]
330
+ name = "scopeguard"
331
+ version = "1.1.0"
332
+ source = "registry+https://github.com/rust-lang/crates.io-index"
333
+ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
334
+
335
+ [[package]]
336
+ name = "serde"
337
+ version = "1.0.157"
338
+ source = "registry+https://github.com/rust-lang/crates.io-index"
339
+ checksum = "707de5fcf5df2b5788fca98dd7eab490bc2fd9b7ef1404defc462833b83f25ca"
340
+
341
+ [[package]]
342
+ name = "shell-words"
343
+ version = "1.1.0"
344
+ source = "registry+https://github.com/rust-lang/crates.io-index"
345
+ checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde"
346
+
347
+ [[package]]
348
+ name = "shlex"
349
+ version = "1.1.0"
350
+ source = "registry+https://github.com/rust-lang/crates.io-index"
351
+ checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3"
352
+
353
+ [[package]]
354
+ name = "smallvec"
355
+ version = "1.10.0"
356
+ source = "registry+https://github.com/rust-lang/crates.io-index"
357
+ checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
358
+
359
+ [[package]]
360
+ name = "syn"
361
+ version = "1.0.109"
362
+ source = "registry+https://github.com/rust-lang/crates.io-index"
363
+ checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
364
+ dependencies = [
365
+ "proc-macro2",
366
+ "quote",
367
+ "unicode-ident",
368
+ ]
369
+
370
+ [[package]]
371
+ name = "tiktoken-rs"
372
+ version = "0.3.2"
373
+ source = "git+https://github.com/IAPark/tiktoken-rs.git#5231fbf4a91d9221a713522e755445d0dde341fa"
374
+ dependencies = [
375
+ "anyhow",
376
+ "base64",
377
+ "bstr",
378
+ "fancy-regex",
379
+ "lazy_static",
380
+ "parking_lot",
381
+ "rustc-hash",
382
+ ]
383
+
384
+ [[package]]
385
+ name = "tiktoken_ruby"
386
+ version = "0.1.0"
387
+ dependencies = [
388
+ "magnus",
389
+ "tiktoken-rs",
390
+ ]
391
+
392
+ [[package]]
393
+ name = "unicode-ident"
394
+ version = "1.0.8"
395
+ source = "registry+https://github.com/rust-lang/crates.io-index"
396
+ checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"
397
+
398
+ [[package]]
399
+ name = "winapi"
400
+ version = "0.3.9"
401
+ source = "registry+https://github.com/rust-lang/crates.io-index"
402
+ checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
403
+ dependencies = [
404
+ "winapi-i686-pc-windows-gnu",
405
+ "winapi-x86_64-pc-windows-gnu",
406
+ ]
407
+
408
+ [[package]]
409
+ name = "winapi-i686-pc-windows-gnu"
410
+ version = "0.4.0"
411
+ source = "registry+https://github.com/rust-lang/crates.io-index"
412
+ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
413
+
414
+ [[package]]
415
+ name = "winapi-x86_64-pc-windows-gnu"
416
+ version = "0.4.0"
417
+ source = "registry+https://github.com/rust-lang/crates.io-index"
418
+ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
419
+
420
+ [[package]]
421
+ name = "windows-sys"
422
+ version = "0.45.0"
423
+ source = "registry+https://github.com/rust-lang/crates.io-index"
424
+ checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
425
+ dependencies = [
426
+ "windows-targets",
427
+ ]
428
+
429
+ [[package]]
430
+ name = "windows-targets"
431
+ version = "0.42.2"
432
+ source = "registry+https://github.com/rust-lang/crates.io-index"
433
+ checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071"
434
+ dependencies = [
435
+ "windows_aarch64_gnullvm",
436
+ "windows_aarch64_msvc",
437
+ "windows_i686_gnu",
438
+ "windows_i686_msvc",
439
+ "windows_x86_64_gnu",
440
+ "windows_x86_64_gnullvm",
441
+ "windows_x86_64_msvc",
442
+ ]
443
+
444
+ [[package]]
445
+ name = "windows_aarch64_gnullvm"
446
+ version = "0.42.2"
447
+ source = "registry+https://github.com/rust-lang/crates.io-index"
448
+ checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
449
+
450
+ [[package]]
451
+ name = "windows_aarch64_msvc"
452
+ version = "0.42.2"
453
+ source = "registry+https://github.com/rust-lang/crates.io-index"
454
+ checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
455
+
456
+ [[package]]
457
+ name = "windows_i686_gnu"
458
+ version = "0.42.2"
459
+ source = "registry+https://github.com/rust-lang/crates.io-index"
460
+ checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
461
+
462
+ [[package]]
463
+ name = "windows_i686_msvc"
464
+ version = "0.42.2"
465
+ source = "registry+https://github.com/rust-lang/crates.io-index"
466
+ checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
467
+
468
+ [[package]]
469
+ name = "windows_x86_64_gnu"
470
+ version = "0.42.2"
471
+ source = "registry+https://github.com/rust-lang/crates.io-index"
472
+ checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
473
+
474
+ [[package]]
475
+ name = "windows_x86_64_gnullvm"
476
+ version = "0.42.2"
477
+ source = "registry+https://github.com/rust-lang/crates.io-index"
478
+ checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
479
+
480
+ [[package]]
481
+ name = "windows_x86_64_msvc"
482
+ version = "0.42.2"
483
+ source = "registry+https://github.com/rust-lang/crates.io-index"
484
+ checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
data/Cargo.toml ADDED
@@ -0,0 +1,7 @@
1
+ # This Cargo.toml is here to let externals tools (IDEs, etc.) know that this is
2
+ # a Rust project. Your extensions dependencies should be added to the Cargo.toml
3
+ # in the ext/ directory.
4
+
5
+ [workspace]
6
+ members = ["./ext/tiktoken_ruby"]
7
+ resolver = "2"
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in tiktoken_ruby.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rake-compiler"
11
+ gem "rb_sys"
12
+
13
+ gem "rspec", "~> 3.0"
14
+
15
+ gem "standard", "~> 1.3"
16
+ gem 'pry', '~> 0.14.2'
data/Gemfile.lock ADDED
@@ -0,0 +1,77 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tiktoken_ruby (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ coderay (1.1.3)
11
+ diff-lcs (1.5.0)
12
+ json (2.6.3)
13
+ language_server-protocol (3.17.0.3)
14
+ method_source (1.0.0)
15
+ parallel (1.22.1)
16
+ parser (3.2.1.1)
17
+ ast (~> 2.4.1)
18
+ pry (0.14.2)
19
+ coderay (~> 1.1)
20
+ method_source (~> 1.0)
21
+ rainbow (3.1.1)
22
+ rake (13.0.6)
23
+ rake-compiler (1.2.1)
24
+ rake
25
+ rb_sys (0.9.68)
26
+ regexp_parser (2.7.0)
27
+ rexml (3.2.5)
28
+ rspec (3.12.0)
29
+ rspec-core (~> 3.12.0)
30
+ rspec-expectations (~> 3.12.0)
31
+ rspec-mocks (~> 3.12.0)
32
+ rspec-core (3.12.1)
33
+ rspec-support (~> 3.12.0)
34
+ rspec-expectations (3.12.2)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.12.0)
37
+ rspec-mocks (3.12.4)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.12.0)
40
+ rspec-support (3.12.0)
41
+ rubocop (1.48.1)
42
+ json (~> 2.3)
43
+ parallel (~> 1.10)
44
+ parser (>= 3.2.0.0)
45
+ rainbow (>= 2.2.2, < 4.0)
46
+ regexp_parser (>= 1.8, < 3.0)
47
+ rexml (>= 3.2.5, < 4.0)
48
+ rubocop-ast (>= 1.26.0, < 2.0)
49
+ ruby-progressbar (~> 1.7)
50
+ unicode-display_width (>= 2.4.0, < 3.0)
51
+ rubocop-ast (1.27.0)
52
+ parser (>= 3.2.1.0)
53
+ rubocop-performance (1.16.0)
54
+ rubocop (>= 1.7.0, < 2.0)
55
+ rubocop-ast (>= 0.4.0)
56
+ ruby-progressbar (1.13.0)
57
+ standard (1.25.1)
58
+ language_server-protocol (~> 3.17.0.2)
59
+ rubocop (= 1.48.1)
60
+ rubocop-performance (= 1.16.0)
61
+ unicode-display_width (2.4.2)
62
+
63
+ PLATFORMS
64
+ arm64-darwin-22
65
+ x86_64-linux
66
+
67
+ DEPENDENCIES
68
+ pry (~> 0.14.2)
69
+ rake (~> 13.0)
70
+ rake-compiler
71
+ rb_sys
72
+ rspec (~> 3.0)
73
+ standard (~> 1.3)
74
+ tiktoken_ruby!
75
+
76
+ BUNDLED WITH
77
+ 2.4.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 IAPark
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ [![Gem Version](https://badge.fury.io/rb/tiktoken_ruby.svg)](https://badge.fury.io/rb/tiktoken_ruby)
2
+ # tiktoken_ruby
3
+
4
+ [Tiktoken](https://github.com/openai/tiktoken) is BPE tokenizer from OpenAI used with their GPT models.
5
+ This is a wrapper around it aimed primarily at enabling accurate counts of GPT model tokens used.
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add tiktoken_ruby
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install tiktoken_ruby
16
+
17
+ ## Usage
18
+
19
+ ```ruby
20
+ encoding = Tiktoken::Encoding.r50k_base
21
+ tokens = encoding.encode("Hello world!")
22
+ puts encoding.decode(tokens)
23
+ ```
24
+
25
+ ## Development
26
+
27
+ 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.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/iapark/tiktoken_ruby.
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "standard/rake"
6
+ require "rake/extensiontask"
7
+ require "rb_sys/extensiontask"
8
+
9
+ GEMSPEC = Gem::Specification.load("tiktoken_ruby.gemspec")
10
+
11
+ RbSys::ExtensionTask.new("tiktoken_ruby", GEMSPEC) do |ext|
12
+ ext.lib_dir = "lib/tiktoken_ruby"
13
+ end
14
+
15
+ RSpec::Core::RakeTask.new(:spec)
16
+
17
+
18
+ task :native, [:platform] do |_t, platform:|
19
+ sh "bundle", "exec", "rb-sys-dock", "--platform", platform, "--build"
20
+ end
21
+
22
+ task build: :compile
23
+
24
+ task default: %i[compile spec standard]
@@ -0,0 +1,14 @@
1
+ [package]
2
+ name = "tiktoken_ruby"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+ authors = ["IAPark <isaac.a.park@gmail.com>"]
6
+ license = "MIT"
7
+ publish = false
8
+
9
+ [lib]
10
+ crate-type = ["cdylib"]
11
+
12
+ [dependencies]
13
+ magnus = { version = "0.4" }
14
+ tiktoken-rs = { git = "https://github.com/IAPark/tiktoken-rs.git" }
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mkmf"
4
+ require "rb_sys/mkmf"
5
+
6
+ create_rust_makefile("tiktoken_ruby/tiktoken_ruby")
@@ -0,0 +1,44 @@
1
+ use std::collections::HashSet;
2
+
3
+ use crate::uncicode_error;
4
+
5
+
6
+ #[magnus::wrap(class = "Tiktoken::Ext::CoreBPE")]
7
+ pub struct CoreBPEWrapper {
8
+ core_bpe: tiktoken_rs::CoreBPE,
9
+ }
10
+
11
+ impl CoreBPEWrapper {
12
+ pub fn new(core_bpe: tiktoken_rs::CoreBPE) -> Self {
13
+ Self { core_bpe }
14
+ }
15
+
16
+ pub fn encode_ordinary(&self, text: String) -> Vec<usize> {
17
+ self.core_bpe.encode_ordinary(text.as_str())
18
+ }
19
+
20
+ pub fn encode(&self, text: String, allowed_special: magnus::RArray) -> Result<Vec<usize>, magnus::Error> {
21
+ let allowed_special: Vec<String> = allowed_special.to_vec()?;
22
+ let allowed_special: Vec<&str> = allowed_special.iter().map(|s| s.as_str()).collect();
23
+ let allowed_special: HashSet<&str> = HashSet::from_iter(allowed_special.iter().cloned());
24
+
25
+ Ok(self.core_bpe.encode(text.as_str(), allowed_special))
26
+ }
27
+
28
+ pub fn encode_with_special_tokens(&self, text: String) -> Vec<usize> {
29
+ self.core_bpe.encode_with_special_tokens(text.as_str())
30
+ }
31
+
32
+ pub fn decode(&self, ids: Vec<usize>) -> Result<String, magnus::Error> {
33
+ self.core_bpe.decode(ids)
34
+ .map_err(|e| {
35
+ let error = match uncicode_error() {
36
+ Ok(error) => error,
37
+ Err(e) => return e
38
+ };
39
+
40
+ magnus::Error::new(error, e.to_string())
41
+ })
42
+
43
+ }
44
+ }
@@ -0,0 +1,52 @@
1
+ mod core_bpe_wrapper;
2
+
3
+ use core_bpe_wrapper::CoreBPEWrapper;
4
+ use magnus::{define_module, function, prelude::*, Error, method, class, RModule, ExceptionClass};
5
+
6
+ fn r50k_base() -> CoreBPEWrapper {
7
+ let core_bpe = tiktoken_rs::r50k_base().unwrap();
8
+ CoreBPEWrapper::new(core_bpe)
9
+ }
10
+ fn p50k_base() -> CoreBPEWrapper {
11
+ let core_bpe = tiktoken_rs::p50k_base().unwrap();
12
+ CoreBPEWrapper::new(core_bpe)
13
+ }
14
+ fn p50k_edit() -> CoreBPEWrapper {
15
+ let core_bpe = tiktoken_rs::p50k_edit().unwrap();
16
+ CoreBPEWrapper::new(core_bpe)
17
+ }
18
+ fn cl100k_base() -> CoreBPEWrapper {
19
+ let core_bpe = tiktoken_rs::cl100k_base().unwrap();
20
+ CoreBPEWrapper::new(core_bpe)
21
+ }
22
+
23
+ fn module() -> Result<RModule, magnus::Error> {
24
+ define_module("Tiktoken")
25
+ }
26
+
27
+ fn uncicode_error() -> Result<ExceptionClass, magnus::Error> {
28
+ module()?.define_error("UnicodeError", magnus::exception::standard_error())
29
+ }
30
+
31
+ #[magnus::init]
32
+ fn init() -> Result<(), Error> {
33
+ let module = module()?;
34
+
35
+ let factory_module = module.define_module("BpeFactory")?;
36
+ factory_module.define_singleton_method("r50k_base", function!(r50k_base, 0))?;
37
+ factory_module.define_singleton_method("p50k_base", function!(p50k_base, 0))?;
38
+ factory_module.define_singleton_method("p50k_base", function!(p50k_edit, 0))?;
39
+ factory_module.define_singleton_method("cl100k_base", function!(cl100k_base, 0))?;
40
+
41
+
42
+ let ext_module = module.define_module("Ext")?;
43
+ let bpe_class = ext_module.define_class("CoreBPE", class::object())?;
44
+
45
+ bpe_class.define_method("encode_ordinary", method!(CoreBPEWrapper::encode_ordinary, 1))?;
46
+ bpe_class.define_method("encode", method!(CoreBPEWrapper::encode, 2))?;
47
+ bpe_class.define_method("encode_with_special_tokens", method!(CoreBPEWrapper::encode_with_special_tokens, 1))?;
48
+
49
+
50
+ bpe_class.define_method("decode", method!(CoreBPEWrapper::decode, 1))?;
51
+ Ok(())
52
+ }
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Tiktoken::Encoding
4
+ def self.method_missing(method)
5
+ Tiktoken::Encoding.new(Tiktoken::BpeFactory.send(method))
6
+ end
7
+
8
+ def initialize(ext_base_bpe)
9
+ @ext_base_bpe = ext_base_bpe
10
+ end
11
+
12
+ def encode_ordinary(text)
13
+ @ext_base_bpe.encode_ordinary(text)
14
+ end
15
+
16
+ def encode(text, allowed_special: [])
17
+ @ext_base_bpe.encode(text, allowed_special)
18
+ end
19
+
20
+ def decode(tokens)
21
+ @ext_base_bpe.decode(tokens)
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tiktoken
4
+ VERSION = "0.0.1"
5
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "tiktoken_ruby/version"
4
+ require_relative "tiktoken_ruby/encoding.rb"
5
+ require_relative "tiktoken_ruby/tiktoken_ruby"
6
+
7
+ module Tiktoken
8
+ class Error < StandardError; end
9
+ end
@@ -0,0 +1,4 @@
1
+ module TiktokenRuby
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/tiktoken_ruby/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "tiktoken_ruby"
7
+ spec.version = Tiktoken::VERSION
8
+ spec.authors = ["IAPark"]
9
+ spec.email = ["isaac.a.park@gmail.com"]
10
+
11
+ spec.summary = "Ruby wrapper for Tiktoken"
12
+ spec.description = "Unofficial Ruby wrapper for Tiktoken by way of the unofficial rust bindings"
13
+ spec.homepage = "https://github.com/IAPark/tiktoken_ruby"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+ spec.required_rubygems_version = ">= 3.3.11"
17
+ spec.platform = Gem::Platform::RUBY
18
+
19
+ #spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = "https://github.com/IAPark/tiktoken_ruby"
23
+ #spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
24
+
25
+ # Specify which files should be added to the gem when it is released.
26
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
27
+ spec.files = Dir.chdir(__dir__) do
28
+ `git ls-files -z`.split("\x0").reject do |f|
29
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
30
+ end
31
+ end
32
+ spec.bindir = "exe"
33
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ["lib"]
35
+ spec.extensions = ["ext/tiktoken_ruby/Cargo.toml"]
36
+
37
+ # Uncomment to register a new dependency of your gem
38
+ # spec.add_dependency "example-gem", "~> 1.0"
39
+ # spec.add_dependency "rb_sys", "~> 0.9"
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
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tiktoken_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - IAPark
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-03-19 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Unofficial Ruby wrapper for Tiktoken by way of the unofficial rust bindings
14
+ email:
15
+ - isaac.a.park@gmail.com
16
+ executables: []
17
+ extensions:
18
+ - ext/tiktoken_ruby/Cargo.toml
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".rspec"
22
+ - ".standard.yml"
23
+ - Cargo.lock
24
+ - Cargo.toml
25
+ - Gemfile
26
+ - Gemfile.lock
27
+ - LICENSE.txt
28
+ - README.md
29
+ - Rakefile
30
+ - ext/tiktoken_ruby/Cargo.toml
31
+ - ext/tiktoken_ruby/extconf.rb
32
+ - ext/tiktoken_ruby/src/core_bpe_wrapper.rs
33
+ - ext/tiktoken_ruby/src/lib.rs
34
+ - lib/tiktoken_ruby.rb
35
+ - lib/tiktoken_ruby/encoding.rb
36
+ - lib/tiktoken_ruby/version.rb
37
+ - sig/tiktoken_ruby.rbs
38
+ - tiktoken_ruby.gemspec
39
+ homepage: https://github.com/IAPark/tiktoken_ruby
40
+ licenses:
41
+ - MIT
42
+ metadata:
43
+ homepage_uri: https://github.com/IAPark/tiktoken_ruby
44
+ source_code_uri: https://github.com/IAPark/tiktoken_ruby
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 2.6.0
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: 3.3.11
59
+ requirements: []
60
+ rubygems_version: 3.4.6
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Ruby wrapper for Tiktoken
64
+ test_files: []