lemukarram/toon
Composer 安装命令:
composer require lemukarram/toon
包简介
A compact, token-efficient data format for AI prompts, developed by Tech With Muk.
README 文档
README
A lightweight, token-efficient data format specifically designed for optimizing AI prompts in Laravel applications. Developed by Mukarram Hussain of Tech with muk.
When sending data to LLMs (like ChatGPT, Claude, or Gemini), standard JSON uses too many tokens due to repeated keys and braces. This package converts your PHP arrays into a highly compact, human-readable "Toon" notation, saving you money and context window space.
Features
- 🚀
jsonToToon: Convert PHP Arrays or JSON to compact notation. - 🔢
countTokens: Estimate the token usage of your strings. - 📉 Smart Compression: Automatically converts lists of objects (like Eloquent collections) into a clean, CSV-style table format to save maximum tokens.
Installation
You can install the package via composer:
composer require lemukarram/toon
The package will automatically register its service provider and facade.
Usage
1. Compressing Data for AI Prompts
Use the Toon facade to convert your data before sending it to an AI API.
use LeMukarram\Toon\Facades\Toon; $data = [ 'user' => 'Mukarram', 'skills' => ['Laravel', 'PHP', 'AI', 'CodeIgniter', 'Shopify'], 'projects' => [ ['name' => 'AI Influencer', 'status' => 'Active'], ['name' => 'Laravel Package', 'status' => 'Done'], ] ]; $promptContext = Toon::jsonToToon($data); /* * The output ($promptContext) will be: * * user: Mukarram * skills: * 0: Laravel * 1: PHP * 2: AI * 3: CodeIgniter * 4: Shopify * projects: * @[2](name,status): * "AI Influencer",Active * "Laravel Package",Done */
2. Estimating Token Usage
Check how many tokens you are saving.
$jsonTokens = Toon::countTokens(json_encode($data)); $toonTokens = Toon::countTokens($promptContext); echo "JSON Tokens: $jsonTokens"; // e.g., ~70 echo "Toon Tokens: $toonTokens"; // e.g., ~45
Credits
- Mukarram Hussain (Tech with muk)
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-10