-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d135371
commit 7aba306
Showing
2 changed files
with
33 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,31 @@ | ||
<?php | ||
|
||
use Rahul900day\Tiktoken\Tiktoken; | ||
require_once __DIR__.'/vendor/autoload.php'; | ||
|
||
require __DIR__.'/vendor/autoload.php'; | ||
use Rahul900day\Tiktoken\Encodings\OpenAiPublic\Cl100KBaseEncoding; | ||
|
||
//$l = new Loader(); | ||
//$data = $l->loadDataGymRanks( | ||
// "https://openaipublic.blob.core.windows.net/gpt-2/encodings/main/vocab.bpe", | ||
// "https://openaipublic.blob.core.windows.net/gpt-2/encodings/main/encoder.json", | ||
// "1ce1664773c50f3e0cc8842619a93edc4624525b728b188a9e0be33b7726adc5", | ||
// "196139668be63f3b5d6574427317ae82f612a97c5d1cdaf36ed2256dbf636783", | ||
//); | ||
class Cl100KIm extends Cl100KBaseEncoding | ||
{ | ||
protected function getName(): string | ||
{ | ||
return 'cl100k_im'; | ||
} | ||
|
||
//$data = $l->load_tiktoken_bpe( | ||
// "https://openaipublic.blob.core.windows.net/encodings/r50k_base.tiktoken", | ||
// "306cd27f03c1a714eca7108e03d66b7dc042abe8c258b44c199a7ed9838dd930", | ||
//); | ||
protected function getSpecialTokens(): array | ||
{ | ||
return [ | ||
...parent::getSpecialTokens(), | ||
"<|im_start|>" => 100264, | ||
"<|im_end|>" => 100265, | ||
]; | ||
} | ||
} | ||
|
||
//var_dump($data); | ||
use Rahul900day\Tiktoken\Registry; | ||
use Rahul900day\Tiktoken\Tiktoken; | ||
|
||
$encoder = Tiktoken::getEncodingForModel('gpt-4'); | ||
$result = $encoder->encode('<|endoftext|>', allowedSpecial: 'all'); | ||
$r2 = $encoder->encode('Hello World'); | ||
Registry::registerCustomEncoding('cl100k_im', new Cl100KIm); | ||
$encoding = Tiktoken::getEncoding('cl100k_im'); | ||
|
||
dd($result, $r2); | ||
// Expect: 100264 | ||
dd($encoding->encode("<|im_start|>", allowedSpecial: 'all')); |