Skip to content

Commit 0e5fe00

Browse files
committed
support o200k_harmony
1 parent 075f518 commit 0e5fe00

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

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",

0 commit comments

Comments
 (0)