cxrxexo / tiktoken
PHP version of tiktoken. PHP 7.4+ required.
Installs: 2 023
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: ^7.4
- symfony/service-contracts: ^2.5
Requires (Dev)
- doctrine/coding-standard: ^11.1
- phpunit/phpunit: ^9.0
- psalm/plugin-phpunit: ^0.18.4
- vimeo/psalm: ^5.12
This package is auto-updated.
Last update: 2024-10-25 04:41:48 UTC
README
This is a port of the tiktoken-php.
Installation
$ composer require cxrxexo/tiktoken
Usage
use CxRxExO\Tiktoken\EncoderProvider; $provider = new EncoderProvider(); $encoder = $provider->getForModel('gpt-3.5-turbo-0301'); $tokens = $encoder->encode('Hello world!'); print_r($tokens); // OUT: [9906, 1917, 0] $encoder = $provider->get('p50k_base'); $tokens = $encoder->encode('Hello world!'); print_r($tokens); // OUT: [15496, 995, 0]
Limitations
- Encoding for GPT-2 is not supported.
- Special tokens (like
<|endofprompt|>
) are not supported.