danny50610 / bpe-tokeniser
openai/tiktoken 的 PHP 版本(大多数情况)
0.2.0
2024-05-18 14:04 UTC
Requires
- php: ^8.1
Requires (Dev)
- phpunit/phpunit: ^10
README
PHP 版本的 openai/tiktoken(大多数情况)
支持的编码
- gpt-3.5-turbo
- gpt-4
- gpt-4o
- 更多...
有关可用编码,请参阅 src/EncodingFactory.php
安装
composer require danny50610/bpe-tokeniser
示例
GPT-4 / GPT-3.5-Turbo (cl100k_base)
use Danny50610\BpeTokeniser\EncodingFactory; $enc = EncodingFactory::createByEncodingName('cl100k_base'); var_dump($enc->encode("hello world")); /** * output: * array(2) { * [0]=> * int(15339) * [1]=> * int(1917) * } */ var_dump($enc->decode($enc->encode("hello world"))); // output: string(11) "hello world"
use Danny50610\BpeTokeniser\EncodingFactory; $enc = EncodingFactory::createByModelName('gpt-3.5-turbo'); var_dump($enc->decode($enc->encode("hello world"))); // output: string(11) "hello world"