-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext-visualizer.html
More file actions
322 lines (291 loc) · 15.4 KB
/
Copy pathcontext-visualizer.html
File metadata and controls
322 lines (291 loc) · 15.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LLM Context Comparison</title>
<meta name="description" content="Compare LLM context window usage side-by-side with live updates and token estimation.">
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>📊</text></svg>">
<script src="https://cdn.tailwindcss.com"></script>
<style>
/* Optional: Add custom base styles or component styles here if needed */
body {
font-family: Inter, sans-serif; /* Example font stack */
}
/* Improve focus visibility */
*:focus-visible {
outline: 2px solid rgb(56 189 248); /* sky-400 */
outline-offset: 2px;
}
textarea {
scrollbar-width: thin;
scrollbar-color: rgb(71 85 105) rgb(51 65 85); /* slate-500 slate-700 */
}
textarea::-webkit-scrollbar {
width: 8px;
}
textarea::-webkit-scrollbar-track {
background: rgb(51 65 85); /* slate-700 */
border-radius: 4px;
}
textarea::-webkit-scrollbar-thumb {
background-color: rgb(71 85 105); /* slate-500 */
border-radius: 4px;
border: 2px solid rgb(51 65 85); /* slate-700 */
}
</style>
</head>
<body class="bg-slate-900">
<div id="app" class="min-h-screen text-slate-100 flex flex-col items-center p-4 sm:p-6 lg:p-8 selection:bg-sky-500 selection:text-white">
<div class="w-full max-w-6xl space-y-8">
<header class="text-center mb-8">
<div class="flex items-center justify-center mb-3">
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="text-sky-400 mr-3">
<polygon points="12 2 2 7 12 12 22 7 12 2"></polygon>
<polyline points="2 17 12 22 22 17"></polyline>
<polyline points="2 12 12 17 22 12"></polyline>
</svg>
<h1 class="text-3xl sm:text-4xl font-bold text-sky-400">LLM Context Comparison</h1>
</div>
<p class="text-slate-400 text-sm sm:text-base">Compare token usage across different models or configurations side-by-side.</p>
</header>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6 lg:gap-8">
<model-visualizer
v-for="config in modelConfigs"
:key="config.id"
:id="config.id"
:name="config.name"
:initial-limit="config.totalTokenLimit"
:initial-input="config.inputText"
:token-limit-options="TOKEN_LIMIT_OPTIONS"
@limit-change="handleModelLimitChange"
@input-change="handleModelInputChange"
></model-visualizer>
</div>
<p class="text-center text-xs text-slate-500 pt-4">
Estimation: 1 token ≈ {{ CHARS_PER_TOKEN }} characters. Actual tokenization may vary per model.<br>
*Model context windows based on publicly available information (April 2025). Gemini 2.5 models listed are currently in Preview status.
</p>
</div>
<footer class="text-center mt-12 text-slate-500 text-sm">
<p>A tool for comparing LLM context window usage.</p>
<p>Model data current as of: April 29, 2025</p>
</footer>
</div>
<script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
<script>
const { createApp, ref, computed, defineComponent } = Vue;
// Updated list reflecting current leading models (April 29, 2025)
const TOKEN_LIMIT_OPTIONS = [
{ label: 'Mistral Large (32K)', value: 32768 },
{ label: 'Meta Llama 3.1 (128K)', value: 128000 },
{ label: 'OpenAI GPT-4o (128K)', value: 128000 },
{ label: 'Anthropic Claude 3.5 Sonnet (200K)', value: 200000 },
// Updated Gemini Models based on Preview versions (April 2025)
{ label: 'Google Gemini 2.5 Flash Preview (1M)', value: 1048576 }, // Using 1024*1024
{ label: 'Google Gemini 2.5 Pro Preview (1M)', value: 1048576 }, // Using 1024*1024
];
const CHARS_PER_TOKEN = 4; // Basic estimation
// === RadialProgress Component ===
const RadialProgress = defineComponent({
props: {
percentage: {
type: Number,
required: true,
default: 0
}
},
setup(props) {
const size = 160; // Corresponds to w-40 h-40
const strokeWidth = 16;
const radius = (size - strokeWidth) / 2;
const circumference = radius * 2 * Math.PI;
const offset = computed(() => circumference - (props.percentage / 100) * circumference);
const progressColor = computed(() => {
if (props.percentage > 90) return 'stroke-red-500';
if (props.percentage > 75) return 'stroke-yellow-500';
return 'stroke-sky-500';
});
return {
size,
strokeWidth,
radius,
circumference,
offset,
progressColor,
roundedPercentage: computed(() => Math.round(props.percentage))
};
},
template: `
<div class="relative w-40 h-40 flex-shrink-0">
<svg :width="size" :height="size" :viewBox="'0 0 ' + size + ' ' + size" class="transform -rotate-90">
<circle
class="text-slate-600"
stroke="currentColor"
fill="transparent"
:stroke-width="strokeWidth"
:r="radius"
:cx="size / 2"
:cy="size / 2"
/>
<circle
:class="[progressColor, 'transition-all duration-300 ease-in-out']"
stroke="currentColor"
fill="transparent"
:stroke-width="strokeWidth"
:stroke-dasharray="circumference"
:stroke-dashoffset="offset"
stroke-linecap="round"
:r="radius"
:cx="size / 2"
:cy="size / 2"
/>
</svg>
<div class="absolute inset-0 flex items-center justify-center">
<span class="text-3xl font-bold text-slate-100">{{ roundedPercentage }}%</span>
</div>
</div>
`
});
// === ModelVisualizer Component ===
const ModelVisualizer = defineComponent({
components: {
'radial-progress': RadialProgress
},
props: {
id: { type: String, required: true },
name: { type: String, required: true },
initialLimit: { type: Number, required: true },
initialInput: { type: String, default: '' },
tokenLimitOptions: { type: Array, required: true }
},
emits: ['limit-change', 'input-change'],
setup(props, { emit }) {
const totalTokenLimit = ref(props.initialLimit);
const inputText = ref(props.initialInput);
const currentTokensUsed = computed(() => Math.ceil(inputText.value.length / CHARS_PER_TOKEN));
const percentageUsed = computed(() => {
if (totalTokenLimit.value === 0) return 0;
// Ensure percentage doesn't exceed 100 visually, even if tokens exceed limit
const rawPercentage = (currentTokensUsed.value / totalTokenLimit.value) * 100;
return Math.min(rawPercentage, 100);
});
const isOverLimit = computed(() => currentTokensUsed.value > totalTokenLimit.value);
const handleLimitChangeInternal = (event) => {
const newLimit = Number(event.target.value);
totalTokenLimit.value = newLimit;
emit('limit-change', { id: props.id, limit: newLimit });
};
const handleInputChangeInternal = (event) => {
const newText = event.target.value;
inputText.value = newText;
emit('input-change', { id: props.id, text: newText });
};
// Format numbers with commas
const formatNumber = (num) => num.toLocaleString();
return {
// State
totalTokenLimit,
inputText,
// Computed
currentTokensUsed,
percentageUsed,
isOverLimit,
// Methods
handleLimitChangeInternal,
handleInputChangeInternal,
formatNumber,
// Constants/Props passed through
CHARS_PER_TOKEN,
};
},
template: `
<div :class="['w-full bg-slate-800 shadow-xl rounded-xl p-6 space-y-6 border', isOverLimit ? 'border-red-600/50' : 'border-slate-700/50']">
<h2 class="text-2xl font-semibold text-center text-sky-400 mb-2">{{ name }}</h2>
<div class="space-y-4">
<div>
<label :for="'tokenLimit-' + id" class="block text-sm font-medium text-slate-300 mb-1">
Token Limit:
</label>
<select
:id="'tokenLimit-' + id"
:value="totalTokenLimit"
@change="handleLimitChangeInternal"
class="w-full bg-slate-700 border border-slate-600 text-slate-100 rounded-md shadow-sm py-2.5 px-3 focus:outline-none focus:ring-2 focus:ring-sky-500 focus:border-sky-500"
>
<option v-for="option in tokenLimitOptions" :key="option.label" :value="option.value"> {{ option.label }} ({{ formatNumber(option.value) }} tokens)
</option>
</select>
</div>
<div>
<label :for="'inputText-' + id" class="block text-sm font-medium text-slate-300 mb-1">
Text for {{ name }}:
</label>
<textarea
:id="'inputText-' + id"
:value="inputText"
@input="handleInputChangeInternal"
:placeholder="'Paste or type text for ' + name + '...'"
rows="8"
class="w-full bg-slate-700 border border-slate-600 text-slate-100 rounded-md shadow-sm p-3 focus:outline-none focus:ring-2 focus:ring-sky-500 focus:border-sky-500 resize-y placeholder-slate-500"
></textarea>
</div>
</div>
<section :class="['flex flex-col md:flex-row items-center justify-between gap-4 p-4 rounded-lg', isOverLimit ? 'bg-red-900/40 border border-red-700' : 'bg-slate-700/80']">
<div class="text-center md:text-left space-y-1 flex-grow">
<h3 :class="['text-lg font-semibold mb-1', isOverLimit ? 'text-red-400' : 'text-sky-400']">Usage</h3>
<p :class="['text-2xl font-bold', isOverLimit ? 'text-red-300' : 'text-slate-100']">
{{ formatNumber(currentTokensUsed) }}
<span :class="['text-base font-medium', isOverLimit ? 'text-red-400' : 'text-slate-400']"> / {{ formatNumber(totalTokenLimit) }} tokens</span>
</p>
<p :class="['text-xs', isOverLimit ? 'text-red-400' : 'text-slate-400']">
{{ formatNumber(inputText.length) }} characters
</p>
<p v-if="isOverLimit" class="text-xs text-red-400 font-medium flex items-center justify-center md:justify-start pt-1">
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="mr-1">
<path d="m21.73 18-8-14a2 2 0 0 0-3.46 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"></path>
<path d="M12 9v4"></path><path d="M12 17h.01"></path>
</svg>
Over limit!
</p>
</div>
<radial-progress :percentage="percentageUsed" />
</section>
</div>
`
});
// === Main Vue App ===
const app = createApp({
setup() {
// Updated defaults to reflect current models (GPT-4o vs Gemini 2.5 Pro Preview)
const modelConfigs = ref([
// Default to GPT-4o (128K) - Index 2
{ id: 'modelA', name: 'Model A', totalTokenLimit: TOKEN_LIMIT_OPTIONS[2].value, inputText: '' },
// Default to Gemini 2.5 Pro Preview (1M) - Index 5
{ id: 'modelB', name: 'Model B', totalTokenLimit: TOKEN_LIMIT_OPTIONS[5].value, inputText: '' },
]);
const handleModelLimitChange = ({ id, limit }) => {
// Parent logic can be added here if needed in response to a limit change
// console.log(`Limit changed for ${id}: ${limit}`);
};
const handleModelInputChange = ({ id, text }) => {
// Parent logic can be added here if needed in response to an input change
// console.log(`Input changed for ${id}: ${text.length} chars`);
};
return {
modelConfigs,
handleModelLimitChange,
handleModelInputChange,
TOKEN_LIMIT_OPTIONS, // Make available to template
CHARS_PER_TOKEN // Make available to template
};
}
});
// Register Components
app.component('model-visualizer', ModelVisualizer);
// RadialProgress is registered within ModelVisualizer
// Mount App
app.mount('#app');
</script>
</body>
</html>