@@ -133,6 +133,19 @@ impl CoreBPEConstructor {
133
133
include_str ! ( "./ranks/cl100k_base.regex.tiktoken" ) ,
134
134
)
135
135
}
136
+
137
+ #[ cfg( feature = "inline" ) ]
138
+ fn o200k_base ( ) -> Self {
139
+ let mut special_tokens = HashMap :: default ( ) ;
140
+ special_tokens. insert ( String :: from ( ENDOFTEXT ) , 199999 ) ;
141
+ special_tokens. insert ( String :: from ( ENDOFPROMPT ) , 200018 ) ;
142
+
143
+ CoreBPEConstructor :: new (
144
+ include_str ! ( "./ranks/o200k_base.compress.tiktoken" ) ,
145
+ Some ( special_tokens) ,
146
+ include_str ! ( "./ranks/o200k_base.regex.tiktoken" ) ,
147
+ )
148
+ }
136
149
}
137
150
138
151
#[ wasm_bindgen]
@@ -179,6 +192,7 @@ impl Tiktoken {
179
192
"p50k_base" => Ok ( CoreBPEConstructor :: p50k_base ( ) ) ,
180
193
"p50k_edit" => Ok ( CoreBPEConstructor :: p50k_edit ( ) ) ,
181
194
"cl100k_base" => Ok ( CoreBPEConstructor :: cl100k_base ( ) ) ,
195
+ "o200k_base" => Ok ( CoreBPEConstructor :: o200k_base ( ) ) ,
182
196
& _ => Err ( JsError :: new ( "Invalid encoding" ) ) ,
183
197
} ?;
184
198
@@ -325,7 +339,7 @@ impl Tiktoken {
325
339
#[ cfg( feature = "inline" ) ]
326
340
#[ wasm_bindgen( typescript_custom_section) ]
327
341
const _: & ' static str = r#"
328
- export type TiktokenEncoding = "gpt2" | "r50k_base" | "p50k_base" | "p50k_edit" | "cl100k_base";
342
+ export type TiktokenEncoding = "gpt2" | "r50k_base" | "p50k_base" | "p50k_edit" | "cl100k_base" | "o200k_base";
329
343
330
344
/**
331
345
* @param {TiktokenEncoding} encoding
@@ -404,6 +418,8 @@ export type TiktokenModel =
404
418
| "gpt-4-1106-preview"
405
419
| "gpt-4-0125-preview"
406
420
| "gpt-4-vision-preview"
421
+ | "gpt-4o"
422
+ | "gpt-4o-2024-05-13"
407
423
408
424
/**
409
425
* @param {TiktokenModel} encoding
@@ -474,6 +490,8 @@ pub fn encoding_for_model(
474
490
"gpt-4-turbo-2024-04-09" => Ok ( "cl100k_base" ) ,
475
491
"gpt-4-turbo-preview" => Ok ( "cl100k_base" ) ,
476
492
"gpt-4-0125-preview" => Ok ( "cl100k_base" ) ,
493
+ "gpt-4o" => Ok ( "o200k_base" ) ,
494
+ "gpt-4o-2024-05-13" => Ok ( "o200k_base" ) ,
477
495
model => Err ( JsError :: new (
478
496
format ! ( "Invalid model: {}" , model. to_string( ) ) . as_str ( ) ,
479
497
) ) ,
0 commit comments