https://github.com/mathsgod/tiktoken-php-wrapper
https://github.com/mathsgod/tiktoken-php-wrapper
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/mathsgod/tiktoken-php-wrapper
- Owner: mathsgod
- Created: 2024-07-26T07:26:17.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-26T07:49:23.000Z (almost 2 years ago)
- Last Synced: 2025-10-13T11:38:10.843Z (8 months ago)
- Language: PHP
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Tiktoken PHP Wrapper
This is a PHP library for the OpenAI tiktoken. It wrap the npm package [tiktoken](https://www.npmjs.com/package/tiktoken) to PHP.
## Installation
```bash
composer require mathsgod/tiktoken-php-wrapper
```
```
npm i tiktoken
```
## Usage
### Encoding
```php
use OpenAI\Tiktoken;
$enc = OpenAI\Tiktoken::EncodingForModel("gpt-4o");
$tokens = $enc->encode("hello world!");
```
### Decoding
```php
use OpenAI\Tiktoken;
$enc = OpenAI\Tiktoken::EncodingForModel("gpt-4o");
$text = $enc->decode([24912,2375]);
```