An open API service indexing awesome lists of open source software.

https://github.com/mathsgod/tiktoken-php-wrapper


https://github.com/mathsgod/tiktoken-php-wrapper

Last synced: 8 months ago
JSON representation

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]);
```