|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
use Squareetlabs\LaravelToon\Services\CompressionMetrics; |
|
6
|
|
|
use Squareetlabs\LaravelToon\Services\CostCalculator; |
|
|
|
|
|
|
7
|
|
|
use Squareetlabs\LaravelToon\Services\TokenAnalyzer; |
|
8
|
|
|
use Squareetlabs\LaravelToon\Services\ToonService; |
|
9
|
|
|
use Squareetlabs\LaravelToon\Toon\EncodeOptions; |
|
10
|
|
|
|
|
11
|
|
|
if (!function_exists('toon')) { |
|
12
|
|
|
/** |
|
13
|
|
|
* Encode data to TOON format |
|
14
|
|
|
*/ |
|
15
|
|
|
function toon(mixed $data, ?EncodeOptions $options = null): string |
|
16
|
|
|
{ |
|
17
|
|
|
return app(ToonService::class)->encode($data, $options); |
|
18
|
|
|
} |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
if (!function_exists('toon_compact')) { |
|
22
|
|
|
/** |
|
23
|
|
|
* Encode data to compact TOON format |
|
24
|
|
|
*/ |
|
25
|
|
|
function toon_compact(mixed $data): string |
|
|
|
|
|
|
26
|
|
|
{ |
|
27
|
|
|
return app(ToonService::class)->encodeCompact($data); |
|
28
|
|
|
} |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
if (!function_exists('toon_readable')) { |
|
32
|
|
|
/** |
|
33
|
|
|
* Encode data to readable TOON format |
|
34
|
|
|
*/ |
|
35
|
|
|
function toon_readable(mixed $data): string |
|
|
|
|
|
|
36
|
|
|
{ |
|
37
|
|
|
return app(ToonService::class)->encodeReadable($data); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
if (!function_exists('toon_tabular')) { |
|
42
|
|
|
/** |
|
43
|
|
|
* Encode data to tabular TOON format |
|
44
|
|
|
*/ |
|
45
|
|
|
function toon_tabular(mixed $data): string |
|
|
|
|
|
|
46
|
|
|
{ |
|
47
|
|
|
return app(ToonService::class)->encodeTabular($data); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
if (!function_exists('toon_decode')) { |
|
52
|
|
|
/** |
|
53
|
|
|
* Decode TOON format to PHP array |
|
54
|
|
|
*/ |
|
55
|
|
|
function toon_decode(string $toon): mixed |
|
|
|
|
|
|
56
|
|
|
{ |
|
57
|
|
|
return app(ToonService::class)->decode($toon); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
if (!function_exists('toon_convert')) { |
|
62
|
|
|
/** |
|
63
|
|
|
* Convert data to TOON format with specified format |
|
64
|
|
|
*/ |
|
65
|
|
|
function toon_convert(mixed $data, string $format = 'readable'): string |
|
|
|
|
|
|
66
|
|
|
{ |
|
67
|
|
|
return app(ToonService::class)->convert($data, $format); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
if (!function_exists('toon_compress')) { |
|
72
|
|
|
/** |
|
73
|
|
|
* Compress and get detailed metrics |
|
74
|
|
|
*/ |
|
75
|
|
|
function toon_compress(mixed $data): array |
|
|
|
|
|
|
76
|
|
|
{ |
|
77
|
|
|
return app(ToonService::class)->compress($data); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
if (!function_exists('toon_metrics')) { |
|
82
|
|
|
/** |
|
83
|
|
|
* Get full compression metrics |
|
84
|
|
|
*/ |
|
85
|
|
|
function toon_metrics(mixed $data): array |
|
|
|
|
|
|
86
|
|
|
{ |
|
87
|
|
|
return app(ToonService::class)->getMetrics($data); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
if (!function_exists('toon_estimate_tokens')) { |
|
92
|
|
|
/** |
|
93
|
|
|
* Estimate tokens in content |
|
94
|
|
|
*/ |
|
95
|
|
|
function toon_estimate_tokens(string $content): int |
|
|
|
|
|
|
96
|
|
|
{ |
|
97
|
|
|
return app(TokenAnalyzer::class)->estimate($content); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
if (!function_exists('toon_compare_json_vs_toon')) { |
|
102
|
|
|
/** |
|
103
|
|
|
* Compare tokens between JSON and TOON |
|
104
|
|
|
*/ |
|
105
|
|
|
function toon_compare_json_vs_toon(mixed $data): array |
|
|
|
|
|
|
106
|
|
|
{ |
|
107
|
|
|
return app(TokenAnalyzer::class)->compareJsonVsToon($data); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
if (!function_exists('toon_analyze')) { |
|
112
|
|
|
/** |
|
113
|
|
|
* Analyze content with token metrics |
|
114
|
|
|
*/ |
|
115
|
|
|
function toon_analyze(string $content): array |
|
|
|
|
|
|
116
|
|
|
{ |
|
117
|
|
|
return app(TokenAnalyzer::class)->analyze($content); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
if (!function_exists('toon_compression_summary')) { |
|
122
|
|
|
/** |
|
123
|
|
|
* Get summary of compression |
|
124
|
|
|
*/ |
|
125
|
|
|
function toon_compression_summary(mixed $data): array |
|
|
|
|
|
|
126
|
|
|
{ |
|
127
|
|
|
return app(CompressionMetrics::class)->summary($data); |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
if (!function_exists('toon_full_metrics')) { |
|
132
|
|
|
/** |
|
133
|
|
|
* Get full compression and token metrics |
|
134
|
|
|
*/ |
|
135
|
|
|
function toon_full_metrics(mixed $data): array |
|
|
|
|
|
|
136
|
|
|
{ |
|
137
|
|
|
return app(CompressionMetrics::class)->full($data); |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
if (!function_exists('toon_benchmark')) { |
|
142
|
|
|
/** |
|
143
|
|
|
* Run performance benchmark |
|
144
|
|
|
*/ |
|
145
|
|
|
function toon_benchmark(mixed $data, int $iterations = 100): array |
|
|
|
|
|
|
146
|
|
|
{ |
|
147
|
|
|
return app(CompressionMetrics::class)->benchmark($data, $iterations); |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
if (!function_exists('toon_cost_estimate')) { |
|
152
|
|
|
/** |
|
153
|
|
|
* Estimate API cost for data |
|
154
|
|
|
*/ |
|
155
|
|
|
function toon_cost_estimate(string $model, mixed $data, string $role = 'input'): array |
|
|
|
|
|
|
156
|
|
|
{ |
|
157
|
|
|
return app(CostCalculator::class)->estimateCost($model, $data, $role); |
|
158
|
|
|
} |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
if (!function_exists('toon_cost_compare_models')) { |
|
162
|
|
|
/** |
|
163
|
|
|
* Compare costs across multiple models |
|
164
|
|
|
*/ |
|
165
|
|
|
function toon_cost_compare_models(mixed $data, string $role = 'input'): array |
|
|
|
|
|
|
166
|
|
|
{ |
|
167
|
|
|
return app(CostCalculator::class)->compareModels($data, $role); |
|
168
|
|
|
} |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
if (!function_exists('toon_cost_with_json_comparison')) { |
|
172
|
|
|
/** |
|
173
|
|
|
* Estimate cost with JSON vs TOON comparison |
|
174
|
|
|
*/ |
|
175
|
|
|
function toon_cost_with_json_comparison(string $model, mixed $data, string $role = 'input'): array |
|
|
|
|
|
|
176
|
|
|
{ |
|
177
|
|
|
return app(CostCalculator::class)->estimateWithJsonComparison($model, $data, $role); |
|
178
|
|
|
} |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
if (!function_exists('toon_budget_analysis')) { |
|
182
|
|
|
/** |
|
183
|
|
|
* Analyze if data fits within budget |
|
184
|
|
|
*/ |
|
185
|
|
|
function toon_budget_analysis(string $model, float $budget, mixed $data, string $role = 'input'): array |
|
|
|
|
|
|
186
|
|
|
{ |
|
187
|
|
|
return app(CostCalculator::class)->budgetAnalysis($model, $budget, $data, $role); |
|
188
|
|
|
} |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths