1. Go to this page and download the library: Download papi-ai/rtk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
papi-ai / rtk example snippets
use PapiAI\Rtk\RtkProxy;
$rtk = new RtkProxy(); // or new RtkProxy('/custom/path/to/rtk')
// Compress captured text (e.g. a tool's stdout) through a named RTK filter
$result = $rtk->optimise($grepOutput, ['filter' => 'grep']);
echo $result->optimised; // compact text
echo $result->savingsPercent(); // e.g. 62.5
// Or run a read-only command through RTK's specialised filter and measure the saving
$result = $rtk->optimiseCommand('git status');
echo $result->tokensBefore, ' -> ', $result->tokensAfter;
// Measuring runs the command twice (raw, then via RTK). Skip the baseline when you only
// want the output: one execution, `tokensBefore` and `savingsPercent()` are then null.
$result = $rtk->optimiseCommand('git status', ['measure' => false]);
use PapiAI\Core\Tool;
$tool = Tool::make(
name: 'git_status',
description: 'Show the working tree status, token-optimised',
parameters: [],
handler: fn () => (new RtkProxy())->optimiseCommand('git status')->optimised,
);
$rtk = new RtkProxy('rtk', new MyTokenizerBackedEstimator());
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.