• Что бы вступить в ряды "Принятый кодер" Вам нужно:
    Написать 10 полезных сообщений или тем и Получить 10 симпатий.
    Для того кто не хочет терять время,может пожертвовать средства для поддержки сервеса, и вступить в ряды VIP на месяц, дополнительная информация в лс.

  • Пользаватели которые будут спамить, уходят в бан без предупреждения. Спам сообщения определяется администрацией и модератором.

  • Гость, Что бы Вы хотели увидеть на нашем Форуме? Изложить свои идеи и пожелания по улучшению форума Вы можете поделиться с нами здесь. ----> Перейдите сюда
  • Все пользователи не прошедшие проверку электронной почты будут заблокированы. Все вопросы с разблокировкой обращайтесь по адресу электронной почте : info@guardianelinks.com . Не пришло сообщение о проверке или о сбросе также сообщите нам.

Introducing TOON for Laravel — A Smarter, Token-Efficient Way to Talk to AI

Sascha Оффлайн

Sascha

Заместитель Администратора
Команда форума
Администратор
Регистрация
9 Май 2015
Сообщения
1,605
Баллы
155

🧠 TOON for Laravel — Compress your prompts, not your ideas


📝 License: MIT

⚡ Laravel: 9+

🐘 PHP: 8.1+

✨ Why TOON?


When building AI-powered Laravel apps, developers often struggle with massive JSON data, expensive token usage, and hard-to-read prompts. That’s where TOON comes in — a Laravel-native data compressor designed to make your AI payloads smaller, cleaner, and easier to understand. 💡

"Compress your prompts, not your ideas."
TOON transforms verbose JSON or PHP arrays into a compact, human-readable format that reduces token cost by up to 70%, while preserving every bit of data.

🚀 Quick Overview

FeatureDescription
🔁 Bidirectional Conversion Convert JSON ⇄ TOON effortlessly
🧩 Readable & Compact YAML-like syntax with improved readability
💰 Token Efficient Save up to 70% of AI token costs
⚙ Laravel Native Seamlessly integrates with facades, commands & service providers
📊 Built-in Analytics Analyze compression & token estimates
🧠 AI Ready Works perfectly with ChatGPT, Gemini, Claude & OpenAI APIs
🧠 What Makes TOON Different?


Unlike typical compression tools, TOON focuses on AI efficiency rather than binary storage. It’s designed for prompt engineering, where readability still matters. You can send structured data to your LLMs while keeping payloads light.

  • ✅ Human-friendly like YAML, but optimized for tokenization.
  • ✅ Built for Laravel developers — not just another JSON formatter.
  • ✅ 100% reversible — decode TOON back into JSON with no loss.
💻 Installation & Setup


composer require sbsaga/toon




Once installed, TOON auto-registers its service provider and facade. Optionally, you can publish its config:


php artisan vendor:publish --provider="Sbsaga\\Toon\\ToonServiceProvider" --tag=config




Config File: config/toon.php


return [
'enabled' => true,
'escape_style' => 'backslash',
'min_rows_to_tabular' => 2,
'max_preview_items' => 200,
];



🧩 Convert JSON → TOON


use Sbsaga\Toon\Facades\Toon;

$data = [
'user' => 'Sagar',
'message' => 'Hello, how are you?',
'tasks' => [
['id' => 1, 'done' => false],
['id' => 2, 'done' => true],
],
];

echo Toon::convert($data);




Output:


user: Sagar
message: Hello\, how are you?
tasks:
items[2]{done,id}:
false,1
true,2



🔄 Convert TOON → JSON


$toon = <<<TOON
user: Sagar
tasks:
items[2]{id,done}:
1,false
2,true
TOON;

print_r(Toon::decode($toon));



📊 Real-World Benchmark

MetricJSONTOONReduction
Size (bytes)7,7182,538🔻 67.12% smaller
Tokens (est.)1,930640💸 ~66.8% fewer tokens

💡 Less data = fewer tokens = lower API bills. Simple math, massive savings.


JSON (7.7 KB)
██████████████████████████████████████████████████████████████████████████

TOON (2.5 KB)
█████████████████



🧪 Quick Laravel Benchmark Route


use Illuminate\Support\Facades\Route;
use Sbsaga\Toon\Facades\Toon;

Route::get('/toon-benchmark', function () {
$json = json_decode(file_get_contents(storage_path('app/users.json')), true);
$toon = Toon::convert($json);

return response()->json([
'json_size' => strlen(json_encode($json)),
'toon_size' => strlen($toon),
'saving_percent' => round(100 - (strlen($toon) / strlen(json_encode($json)) * 100), 2),
'toon_preview' => $toon,
]);
});



🧰 Artisan Commands


php artisan toon:convert storage/data.json
php artisan toon:convert storage/data.toon --decode
php artisan toon:convert storage/data.json --output=storage/result.toon



🌍 Real Use Cases

Use CaseBenefit
🤖 AI Prompt Engineering Compress structured inputs for ChatGPT & Gemini
💬 LLM Context Management Fit more data within token limits
🧾 Readable Logging Store structured data compactly
⚙ Microservice Communication Reduce payload size across services
🔑 SEO & AI Integration Keywords


laravel, php, ai, chatgpt, openai, llm, gemini, mistral, anthropic, laravel-ai, laravel-openai, laravel-llm, php-ai, token-optimizer, prompt-engineering, api-optimization, backend-optimization, laravel-packages, php-development, web-development, json-compression, data-compression, efficient-coding, developer-tools, performance-optimization, api-integration, php-8.1

❤ Final Thoughts


If you build AI tools with Laravel, TOON is a game-changer. It helps you:

  • 🚀 Send more context without hitting token limits
  • 🧩 Keep your data clean, readable, and reversible
  • 💸 Save real money on AI API usage
🧠 “Compress your prompts, not your ideas.” — Let your code (and AI) breathe.
📦 GitHub:

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



📦 Packagist:

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.




Built with ❤ for Laravel Developers who love clean, smart AI integrations.



Источник:

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

 
Вверх Снизу