-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.js
More file actions
22 lines (19 loc) · 847 Bytes
/
Copy pathmodels.js
File metadata and controls
22 lines (19 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
'use strict';
// Detects context window size from model id bracket notation (e.g. opus[1m], sonnet[500k]).
// Falls back to 200k (Claude default) when no bracket suffix is present.
// If CC already provides `context_window.context_window_size`, prefer that via `fromInput`.
function detectContextSize(modelId, fromInput) {
if (fromInput && Number.isFinite(fromInput) && fromInput > 0) return fromInput;
const id = String(modelId || '').toLowerCase();
const m = id.match(/\[(\d+)(k|m)\]/);
if (m) {
const n = parseInt(m[1], 10);
if (Number.isFinite(n) && n > 0) return m[2] === 'm' ? n * 1_000_000 : n * 1_000;
}
return 200_000;
}
function formatContextLabel(size) {
const k = Math.floor(size / 1000);
return k >= 1000 ? `${Math.floor(k / 1000)}M` : `${k}k`;
}
module.exports = { detectContextSize, formatContextLabel };