burnmydays commited on
Commit
38e6bef
·
1 Parent(s): c38609e

Create import React, { useState } from 'react';.js

Browse files
import React, { useState } from 'react';.js ADDED
@@ -0,0 +1,245 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React, { useState } from 'react';
2
+ import { BarChart, Bar, LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer, AreaChart, Area, ComposedChart } from 'recharts';
3
+ import { TrendingDown, TrendingUp, Activity, FileText, ArrowDownRight, Zap } from 'lucide-react';
4
+
5
+ const TokenReport = () => {
6
+ const [activeTab, setActiveTab] = useState('overview');
7
+
8
+ // --- DATA PREPARATION ---
9
+
10
+ // Raw data derived from user inputs
11
+ const timeSeriesData = [
12
+ { turn: 'Turn 1', Baseline1: 45, Baseline2: 52, Enforce1: 48, Enforce2: 46, Enforce3: 55 },
13
+ { turn: 'Turn 2', Baseline1: 49, Baseline2: 68, Enforce1: 37, Enforce2: 33, Enforce3: 53 },
14
+ { turn: 'Turn 3', Baseline1: 57, Baseline2: 62, Enforce1: 35, Enforce2: 19, Enforce3: 32 },
15
+ { turn: 'Turn 4', Baseline1: 42, Baseline2: 63, Enforce1: 19, Enforce2: 13, Enforce3: 10 },
16
+ { turn: 'Turn 5', Baseline1: 37, Baseline2: 69, Enforce1: 17, Enforce2: 12, Enforce3: 5 },
17
+ ];
18
+
19
+ const totalComparisonData = [
20
+ { name: 'Baseline 1', total: 230, avg: 46, type: 'Standard' },
21
+ { name: 'Baseline 2', total: 316, avg: 63, type: 'Standard' },
22
+ { name: 'Enforcement 1', total: 156, avg: 31.2, type: 'Optimized' },
23
+ { name: 'Enforcement 2', total: 123, avg: 24.6, type: 'Optimized' }, // Recalculated sum based on rows
24
+ { name: 'Enforcement 3', total: 155, avg: 31, type: 'Optimized' },
25
+ ];
26
+
27
+ // Specific calculation for Test 1 (3 turn subtotal requested by user)
28
+ const baseline1SubtotalInput = 54;
29
+ const baseline1SubtotalOutput = 97;
30
+ const baseline1IncreaseRaw = baseline1SubtotalOutput - baseline1SubtotalInput;
31
+ const baseline1IncreasePercent = ((baseline1IncreaseRaw / baseline1SubtotalInput) * 100).toFixed(1);
32
+
33
+ // Efficiency Calculation (Baseline 2 vs Best Enforcement)
34
+ const bestReduction = ((316 - 123) / 316 * 100).toFixed(1);
35
+
36
+ return (
37
+ <div className="min-h-screen bg-slate-50 text-slate-900 font-sans p-4 md:p-8">
38
+
39
+ {/* HEADER */}
40
+ <div className="max-w-6xl mx-auto mb-8">
41
+ <h1 className="text-3xl font-bold text-slate-800 mb-2">LLM Token Economy Report</h1>
42
+ <p className="text-slate-600">Analyzing the "Mirroring Effect" vs. "Enforcement Protocols" in conversational agents.</p>
43
+ </div>
44
+
45
+ {/* KPI CARDS */}
46
+ <div className="max-w-6xl mx-auto grid grid-cols-1 md:grid-cols-3 gap-4 mb-8">
47
+ <div className="bg-white p-6 rounded-xl shadow-sm border border-slate-200">
48
+ <div className="flex items-center justify-between mb-4">
49
+ <h3 className="text-sm font-semibold text-slate-500 uppercase">Baseline Bloat</h3>
50
+ <TrendingUp className="text-red-500" size={20} />
51
+ </div>
52
+ <div className="text-4xl font-bold text-slate-800">+{baseline1IncreasePercent}%</div>
53
+ <p className="text-sm text-slate-500 mt-2">Token increase in Baseline Test 1 (Input vs Output)</p>
54
+ </div>
55
+
56
+ <div className="bg-white p-6 rounded-xl shadow-sm border border-slate-200">
57
+ <div className="flex items-center justify-between mb-4">
58
+ <h3 className="text-sm font-semibold text-slate-500 uppercase">Max Efficiency</h3>
59
+ <Zap className="text-green-500" size={20} />
60
+ </div>
61
+ <div className="text-4xl font-bold text-slate-800">{bestReduction}%</div>
62
+ <p className="text-sm text-slate-500 mt-2">Reduction in total volume (Baseline 2 vs. Enforcement 2)</p>
63
+ </div>
64
+
65
+ <div className="bg-white p-6 rounded-xl shadow-sm border border-slate-200">
66
+ <div className="flex items-center justify-between mb-4">
67
+ <h3 className="text-sm font-semibold text-slate-500 uppercase">Avg Decay Rate</h3>
68
+ <ArrowDownRight className="text-blue-500" size={20} />
69
+ </div>
70
+ <div className="text-4xl font-bold text-slate-800">-71%</div>
71
+ <p className="text-sm text-slate-500 mt-2">Token drop from Turn 1 to Turn 5 in Enforcement models</p>
72
+ </div>
73
+ </div>
74
+
75
+ {/* TABS & CONTENT */}
76
+ <div className="max-w-6xl mx-auto bg-white rounded-xl shadow-sm border border-slate-200 overflow-hidden">
77
+ <div className="flex border-b border-slate-200">
78
+ <button
79
+ onClick={() => setActiveTab('overview')}
80
+ className={`px-6 py-4 font-medium text-sm focus:outline-none ${activeTab === 'overview' ? 'bg-slate-50 text-blue-600 border-b-2 border-blue-600' : 'text-slate-500 hover:text-slate-800'}`}
81
+ >
82
+ Total Comparison
83
+ </button>
84
+ <button
85
+ onClick={() => setActiveTab('velocity')}
86
+ className={`px-6 py-4 font-medium text-sm focus:outline-none ${activeTab === 'velocity' ? 'bg-slate-50 text-blue-600 border-b-2 border-blue-600' : 'text-slate-500 hover:text-slate-800'}`}
87
+ >
88
+ Turn Velocity
89
+ </button>
90
+ <button
91
+ onClick={() => setActiveTab('detailed')}
92
+ className={`px-6 py-4 font-medium text-sm focus:outline-none ${activeTab === 'detailed' ? 'bg-slate-50 text-blue-600 border-b-2 border-blue-600' : 'text-slate-500 hover:text-slate-800'}`}
93
+ >
94
+ Detailed Analysis
95
+ </button>
96
+ </div>
97
+
98
+ <div className="p-6 md:p-8">
99
+
100
+ {/* TAB 1: TOTAL COMPARISON */}
101
+ {activeTab === 'overview' && (
102
+ <div className="animate-fade-in">
103
+ <h2 className="text-xl font-bold text-slate-800 mb-6">Total Token Load (5 Turns)</h2>
104
+ <div className="h-80 w-full mb-8">
105
+ <ResponsiveContainer width="100%" height="100%">
106
+ <BarChart data={totalComparisonData} layout="vertical" margin={{ top: 5, right: 30, left: 40, bottom: 5 }}>
107
+ <CartesianGrid strokeDasharray="3 3" horizontal={true} vertical={true} />
108
+ <XAxis type="number" />
109
+ <YAxis dataKey="name" type="category" width={100} tick={{fontSize: 12}} />
110
+ <Tooltip
111
+ contentStyle={{ backgroundColor: '#fff', borderRadius: '8px', border: '1px solid #e2e8f0' }}
112
+ cursor={{fill: 'transparent'}}
113
+ />
114
+ <Legend />
115
+ <Bar dataKey="total" name="Total Tokens" fill="#3b82f6" radius={[0, 4, 4, 0]}>
116
+ {
117
+ totalComparisonData.map((entry, index) => (
118
+ <cell key={`cell-${index}`} fill={entry.type === 'Standard' ? '#ef4444' : '#22c55e'} />
119
+ ))
120
+ }
121
+ </Bar>
122
+ </BarChart>
123
+ </ResponsiveContainer>
124
+ </div>
125
+ <div className="bg-slate-50 p-4 rounded-lg border border-slate-200">
126
+ <h4 className="font-semibold text-slate-700 mb-2">Key Finding:</h4>
127
+ <p className="text-slate-600 text-sm">
128
+ Standard LLM behavior ("Baseline") resulted in a <strong>mirroring effect</strong>, where the model repeats and expands upon information, causing token count to grow or remain stagnant high. The "Enforcement" protocols reduced total token load by up to <strong>61%</strong> compared to the worst-case baseline.
129
+ </p>
130
+ </div>
131
+ </div>
132
+ )}
133
+
134
+ {/* TAB 2: VELOCITY */}
135
+ {activeTab === 'velocity' && (
136
+ <div className="animate-fade-in">
137
+ <h2 className="text-xl font-bold text-slate-800 mb-6">Token Decay vs. Stagnation</h2>
138
+ <p className="text-sm text-slate-500 mb-4">Tracking total tokens (Input + Output) per turn.</p>
139
+ <div className="h-80 w-full mb-8">
140
+ <ResponsiveContainer width="100%" height="100%">
141
+ <LineChart data={timeSeriesData} margin={{ top: 5, right: 30, left: 20, bottom: 5 }}>
142
+ <CartesianGrid strokeDasharray="3 3" vertical={false} />
143
+ <XAxis dataKey="turn" />
144
+ <YAxis />
145
+ <Tooltip contentStyle={{ backgroundColor: '#fff', borderRadius: '8px', border: '1px solid #e2e8f0' }} />
146
+ <Legend />
147
+
148
+ {/* Baselines (Red/Orange) */}
149
+ <Line type="monotone" dataKey="Baseline1" stroke="#ef4444" strokeWidth={3} dot={{r: 4}} />
150
+ <Line type="monotone" dataKey="Baseline2" stroke="#f97316" strokeWidth={3} dot={{r: 4}} />
151
+
152
+ {/* Enforcement (Greens/Blues) */}
153
+ <Line type="monotone" dataKey="Enforce1" stroke="#3b82f6" strokeWidth={2} strokeDasharray="5 5" />
154
+ <Line type="monotone" dataKey="Enforce2" stroke="#22c55e" strokeWidth={2} strokeDasharray="5 5" />
155
+ <Line type="monotone" dataKey="Enforce3" stroke="#0ea5e9" strokeWidth={2} strokeDasharray="5 5" />
156
+ </LineChart>
157
+ </ResponsiveContainer>
158
+ </div>
159
+ <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
160
+ <div className="bg-red-50 p-4 rounded-lg border border-red-100">
161
+ <h4 className="font-semibold text-red-700 mb-1">Baseline Trend</h4>
162
+ <p className="text-red-600 text-xs">
163
+ Remains consistently high (40-70 tokens/turn). The model feels "obligated" to reply with conversational filler ("Got it", "Just to confirm"), maintaining high volume.
164
+ </p>
165
+ </div>
166
+ <div className="bg-green-50 p-4 rounded-lg border border-green-100">
167
+ <h4 className="font-semibold text-green-700 mb-1">Enforcement Trend</h4>
168
+ <p className="text-green-600 text-xs">
169
+ Aggressive decay. By Turn 4 and 5, the model enters a "maintenance mode," utilizing only 5-15 tokens per turn to sustain the context.
170
+ </p>
171
+ </div>
172
+ </div>
173
+ </div>
174
+ )}
175
+
176
+ {/* TAB 3: DETAILED ANALYSIS */}
177
+ {activeTab === 'detailed' && (
178
+ <div className="animate-fade-in space-y-8">
179
+
180
+ {/* Question 1 Answer */}
181
+ <div className="bg-indigo-50 border border-indigo-100 rounded-lg p-6">
182
+ <h3 className="text-lg font-bold text-indigo-900 mb-2">Answer to your Request: Baseline 1 Inflation</h3>
183
+ <p className="text-indigo-800 text-sm mb-4">
184
+ "What is the % increase on this?" (Based on the first 3 turns of Baseline 1)
185
+ </p>
186
+ <div className="flex items-end gap-2 mb-2">
187
+ <span className="text-3xl font-bold text-indigo-700">79.6%</span>
188
+ <span className="text-sm text-indigo-600 mb-2">Increase</span>
189
+ </div>
190
+ <div className="w-full bg-indigo-200 rounded-full h-2.5 mb-2">
191
+ <div className="bg-indigo-600 h-2.5 rounded-full" style={{ width: '79.6%' }}></div>
192
+ </div>
193
+ <ul className="list-disc list-inside text-xs text-indigo-800 space-y-1">
194
+ <li><strong>Input Subtotal:</strong> 54 tokens</li>
195
+ <li><strong>Output Subtotal:</strong> 97 tokens</li>
196
+ <li><strong>Net Increase:</strong> +43 tokens</li>
197
+ </ul>
198
+ </div>
199
+
200
+ {/* Data Table */}
201
+ <div>
202
+ <h3 className="text-lg font-bold text-slate-800 mb-4">Turn-by-Turn Data Breakdown</h3>
203
+ <div className="overflow-x-auto">
204
+ <table className="min-w-full divide-y divide-slate-200 border border-slate-200 rounded-lg">
205
+ <thead className="bg-slate-50">
206
+ <tr>
207
+ <th className="px-6 py-3 text-left text-xs font-medium text-slate-500 uppercase tracking-wider">Test Name</th>
208
+ <th className="px-6 py-3 text-left text-xs font-medium text-slate-500 uppercase tracking-wider">Turn 1</th>
209
+ <th className="px-6 py-3 text-left text-xs font-medium text-slate-500 uppercase tracking-wider">Turn 2</th>
210
+ <th className="px-6 py-3 text-left text-xs font-medium text-slate-500 uppercase tracking-wider">Turn 3</th>
211
+ <th className="px-6 py-3 text-left text-xs font-medium text-slate-500 uppercase tracking-wider">Turn 4</th>
212
+ <th className="px-6 py-3 text-left text-xs font-medium text-slate-500 uppercase tracking-wider">Turn 5</th>
213
+ <th className="px-6 py-3 text-left text-xs font-medium text-slate-900 uppercase tracking-wider">Avg</th>
214
+ </tr>
215
+ </thead>
216
+ <tbody className="bg-white divide-y divide-slate-200">
217
+ {[
218
+ { name: 'Baseline 1', data: [45, 49, 57, 42, 37], avg: 46 },
219
+ { name: 'Baseline 2', data: [52, 68, 62, 63, 69], avg: 63 },
220
+ { name: 'Enforce 1', data: [48, 37, 35, 19, 17], avg: 31 },
221
+ { name: 'Enforce 2', data: [46, 33, 19, 13, 12], avg: 24 },
222
+ { name: 'Enforce 3', data: [55, 53, 32, 10, 5], avg: 30 },
223
+ ].map((row, idx) => (
224
+ <tr key={idx} className={idx < 2 ? 'bg-red-50/30' : 'bg-green-50/30'}>
225
+ <td className="px-6 py-4 whitespace-nowrap text-sm font-medium text-slate-900">{row.name}</td>
226
+ {row.data.map((val, i) => (
227
+ <td key={i} className="px-6 py-4 whitespace-nowrap text-sm text-slate-500">{val}</td>
228
+ ))}
229
+ <td className="px-6 py-4 whitespace-nowrap text-sm font-bold text-slate-800">{row.avg}</td>
230
+ </tr>
231
+ ))}
232
+ </tbody>
233
+ </table>
234
+ </div>
235
+ </div>
236
+ </div>
237
+ )}
238
+
239
+ </div>
240
+ </div>
241
+ </div>
242
+ );
243
+ };
244
+
245
+ export default TokenReport;