Skip to content

Commit 775fa75

Browse files
committed
✨ feat(newapi): vendor/model sync; K/M context; move ratios path
Add a NewAPI model-management sync suite and restructure outputs: - Endpoints (under /api/newapi/): - vendors.json — rows aligned to `vendors` table - models.json — rows aligned to `models` table - ratio_config-v1-base.json — pricing ratios payload - build.js: - Centralize all NewAPI generation into one block - Add helpers: buildNewApiSyncPayload(), buildNewApiTags(), formatTokensToKM() - Include context size in tags using K/M notation (e.g., 128K, 1M; no prefix) - Unify Markdown table limits via K/M formatting (1,000K becomes 1M) - docs: - Update docs/index.md to list new endpoints and new ratios path - Update README.md & README.zh-CN.md links/descriptions BREAKING CHANGE: pricing ratios endpoint moved from /api/newapi-ratio_config-v1-base.json to /api/newapi/ratio_config-v1-base.json (Update consumers accordingly; payload shape unchanged.)
1 parent 2d7a5ea commit 775fa75

File tree

2 files changed

+38
-16
lines changed

2 files changed

+38
-16
lines changed

scripts/build.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const {
1414
copyDirSyncIfExists,
1515
sanitizeFileSegment,
1616
removeNonJsonFiles,
17+
writeTextIfChanged,
18+
formatTokensToKM,
1719
} = require('./utils');
1820

1921
const ROOT = path.resolve(__dirname, '..');
@@ -175,7 +177,8 @@ function formatDetails(model) {
175177

176178
// Format context/output limits for display
177179
function formatLimit(value) {
178-
return value ? `${(value / 1000).toFixed(0)}K` : '-';
180+
const s = formatTokensToKM(value);
181+
return s || '-';
179182
}
180183

181184
// Escape pipe characters for markdown table safety
@@ -498,20 +501,6 @@ This page displays comprehensive information about all LLM providers and models,
498501
return markdown;
499502
}
500503

501-
// Write text file if content has changed
502-
function writeTextIfChanged(filePath, content, { dryRun = false } = {}) {
503-
ensureDirSync(path.dirname(filePath));
504-
505-
const existing = fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf8') : null;
506-
const isChanged = existing !== content;
507-
508-
if (!dryRun && isChanged) {
509-
fs.writeFileSync(filePath, content, 'utf8');
510-
}
511-
512-
return isChanged;
513-
}
514-
515504
main().catch((err) => {
516505
console.error(err);
517506
process.exit(1);
@@ -535,6 +524,10 @@ function buildNewApiTags(model) {
535524
if ([...inMods, ...outMods].includes('image')) tagSet.add('vision');
536525
if ([...inMods, ...outMods].includes('audio')) tagSet.add('audio');
537526
if (model.open_weights) tagSet.add('open-weights');
527+
// Add context window tag: <K/M>
528+
const ctx = model.limit?.context;
529+
const ctxKM = formatTokensToKM(ctx);
530+
if (ctxKM) tagSet.add(ctxKM);
538531
return Array.from(tagSet).join(',');
539532
}
540533

@@ -578,4 +571,4 @@ function buildNewApiSyncPayload(allModelsData) {
578571
}
579572

580573
return { vendors, models };
581-
}
574+
}

scripts/utils.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,33 @@ function removeNonJsonFiles(dirPath, options = {}) {
152152
return { removed };
153153
}
154154

155+
// Write text file if content has changed
156+
function writeTextIfChanged(filePath, content, { dryRun = false } = {}) {
157+
ensureDirSync(path.dirname(filePath));
158+
159+
const existing = fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf8') : null;
160+
const isChanged = existing !== content;
161+
162+
if (!dryRun && isChanged) {
163+
fs.writeFileSync(filePath, content, 'utf8');
164+
}
165+
166+
return isChanged;
167+
}
168+
169+
// Format numeric token count to K/M string (e.g., 128K, 1M, 1.5M)
170+
function formatTokensToKM(value) {
171+
if (typeof value !== 'number' || !isFinite(value) || value <= 0) return null;
172+
if (value >= 1000000) {
173+
const m = value / 1000000;
174+
const out = Number.isInteger(m) ? String(m) : m.toFixed(1);
175+
return `${out}M`;
176+
}
177+
const k = value / 1000;
178+
const out = Math.round(k);
179+
return `${out}K`;
180+
}
181+
155182
module.exports = {
156183
ensureDirSync,
157184
readJSONSafe,
@@ -164,6 +191,8 @@ module.exports = {
164191
copyDirSyncIfExists,
165192
sanitizeFileSegment,
166193
removeNonJsonFiles,
194+
writeTextIfChanged,
195+
formatTokensToKM,
167196
};
168197

169198

0 commit comments

Comments
 (0)