cxrxexo/tiktoken

PHP version of tiktoken. PHP 7.4+ required.

1.0.1 2023-06-24 09:38 UTC

This package is auto-updated.

Last update: 2024-10-25 04:41:48 UTC


README

Packagist Version Build status License

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.

License

MIT