Skip to content

This is a port of the tiktoken-php compatible with PHP 7.4+

License

Notifications You must be signed in to change notification settings

CxRxExO/tiktoken-php-7.4

Repository files navigation

tiktoken-php

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

About

This is a port of the tiktoken-php compatible with PHP 7.4+

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages