Skip to content

Commit d53e973

Browse files
authored
Merge pull request #87 from IAPark/oss-mods
Support `o200k_harmony`
2 parents 761d2e2 + 4dce94b commit d53e973

File tree

6 files changed

+64
-109
lines changed

6 files changed

+64
-109
lines changed

Cargo.lock

Lines changed: 48 additions & 104 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
tiktoken_ruby (0.0.12)
4+
tiktoken_ruby (0.0.13)
55
rb_sys (~> 0.9)
66

77
GEM

ext/tiktoken_ruby/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ crate-type = ["cdylib"]
1212
[dependencies]
1313
magnus = { version = "0.8.2" }
1414
rb-sys = { version = "0.9.117", features = ["stable-api-compiled-fallback"] }
15-
tiktoken-rs = { version = "0.7.0" }
15+
tiktoken-rs = { version = "0.9.0" }

ext/tiktoken_ruby/src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,20 @@ fn o200k_base() -> CoreBPEWrapper {
2525
CoreBPEWrapper::new(core_bpe)
2626
}
2727

28+
fn o200k_harmony() -> CoreBPEWrapper {
29+
let core_bpe = tiktoken_rs::o200k_harmony().unwrap();
30+
CoreBPEWrapper::new(core_bpe)
31+
}
32+
2833
fn module() -> Result<RModule, magnus::Error> {
2934
Ruby::get().unwrap().define_module("Tiktoken")
3035
}
3136

3237
fn uncicode_error() -> Result<ExceptionClass, magnus::Error> {
33-
module()?.define_error("UnicodeError", Ruby::get().unwrap().exception_standard_error())
38+
module()?.define_error(
39+
"UnicodeError",
40+
Ruby::get().unwrap().exception_standard_error(),
41+
)
3442
}
3543

3644
#[magnus::init]
@@ -43,6 +51,7 @@ fn init() -> Result<(), Error> {
4351
factory_module.define_singleton_method("p50k_edit", function!(p50k_edit, 0))?;
4452
factory_module.define_singleton_method("cl100k_base", function!(cl100k_base, 0))?;
4553
factory_module.define_singleton_method("o200k_base", function!(o200k_base, 0))?;
54+
factory_module.define_singleton_method("o200k_harmony", function!(o200k_harmony, 0))?;
4655

4756
let ext_module = module.define_module("Ext")?;
4857
let bpe_class = ext_module.define_class("CoreBPE", Ruby::get().unwrap().class_object())?;

lib/tiktoken_ruby.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ def list_model_names
6565
:p50k_base,
6666
:p50k_edit,
6767
:cl100k_base,
68-
:o200k_base
68+
:o200k_base,
69+
:o200k_harmony
6970
]
7071

7172
# taken from the python library here https://github.com/openai/tiktoken/blob/main/tiktoken/model.py
@@ -143,6 +144,7 @@ def list_model_names
143144
"gpt-4-": "cl100k_base", # e.g., gpt-4-0314, etc., plus gpt-4-32k
144145
"gpt-3.5-turbo-": "cl100k_base", # e.g, gpt-3.5-turbo-0301, -0401, etc.
145146
"gpt-35-turbo-": "cl100k_base", # Azure deployment name
147+
"gpt-oss-": "o200k_harmony",
146148
# fine-tuned
147149
"ft:gpt-4o": "cl100k_base",
148150
"ft:gpt-4": "cl100k_base",

lib/tiktoken_ruby/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Tiktoken
4-
VERSION = "0.0.12"
4+
VERSION = "0.0.13"
55
end

0 commit comments

Comments
 (0)