-
Notifications
You must be signed in to change notification settings - Fork 382
Expand file tree
/
Copy pathgenerate-model-tables.js
More file actions
262 lines (228 loc) · 9.4 KB
/
generate-model-tables.js
File metadata and controls
262 lines (228 loc) · 9.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
#!/usr/bin/env node
/**
* Model Tables Documentation Generator
*
* Reads the built-in model alias map and model multipliers from JSON data files
* and generates an intuitively readable reference page with markdown tables.
*
* Usage:
* node scripts/generate-model-tables.js
*
* Inputs:
* pkg/cli/data/model_aliases.json – Built-in alias → pattern mappings
* pkg/cli/data/model_multipliers.json – Per-model Effective Token multipliers
*
* Output:
* docs/src/content/docs/reference/model-tables.md
*/
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const ROOT = path.resolve(__dirname, "..");
const ALIASES_PATH = path.join(ROOT, "pkg/workflow/data/model_aliases.json");
const MULTIPLIERS_PATH = path.join(ROOT, "pkg/cli/data/model_multipliers.json");
const OUTPUT_PATH = path.join(ROOT, "docs/src/content/docs/reference/model-tables.md");
// ---------------------------------------------------------------------------
// Load data
// ---------------------------------------------------------------------------
/**
* Read and parse a JSON file, with a clear error message on failure.
* @param {string} filePath
* @returns {any}
*/
function readJSON(filePath) {
let raw;
try {
raw = fs.readFileSync(filePath, "utf-8");
} catch (err) {
console.error(`Error: could not read ${filePath}: ${err.message}`);
process.exit(1);
}
try {
return JSON.parse(raw);
} catch (err) {
console.error(`Error: invalid JSON in ${filePath}: ${err.message}`);
process.exit(1);
}
}
const aliasesData = readJSON(ALIASES_PATH);
const multipliersData = readJSON(MULTIPLIERS_PATH);
const aliases = aliasesData.aliases;
const multipliers = multipliersData.multipliers;
const tokenClassWeights = multipliersData.token_class_weights;
const referenceModel = multipliersData.reference_model;
// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------
/**
* Group aliases into "vendor" aliases (patterns using glob wildcards) and
* "meta" aliases (patterns that reference other aliases by name, with no slash).
*/
function classifyAliases(aliasMap) {
const vendor = [];
const meta = [];
for (const [alias, patterns] of Object.entries(aliasMap)) {
const isMetaOnly = patterns.every(p => !p.includes("/"));
if (isMetaOnly) {
meta.push({ alias, resolves: patterns });
} else {
vendor.push({ alias, patterns });
}
}
return { vendor, meta };
}
/**
* Group multipliers into provider sections based on model name prefix.
*/
function groupMultipliers(mults) {
const groups = {
Anthropic: [],
OpenAI: [],
"OpenAI Reasoning": [],
Google: [],
Other: [],
};
for (const [model, value] of Object.entries(mults)) {
if (model.startsWith("claude-")) {
groups["Anthropic"].push({ model, value });
} else if (/^o[0-9]/.test(model)) {
groups["OpenAI Reasoning"].push({ model, value });
} else if (model.startsWith("gpt-")) {
groups["OpenAI"].push({ model, value });
} else if (model.startsWith("gemini-")) {
groups["Google"].push({ model, value });
} else {
groups["Other"].push({ model, value });
}
}
// Remove empty groups
return Object.fromEntries(Object.entries(groups).filter(([, rows]) => rows.length > 0));
}
// ---------------------------------------------------------------------------
// Markdown generators
// ---------------------------------------------------------------------------
function generateAliasTable(vendorAliases) {
const lines = [];
lines.push("| Alias | Fallback patterns (tried in order) |");
lines.push("|-------|-------------------------------------|");
for (const { alias, patterns } of vendorAliases) {
const formattedPatterns = patterns.map(p => `\`${p}\``).join(", ");
lines.push(`| \`${alias}\` | ${formattedPatterns} |`);
}
return lines.join("\n");
}
function generateMetaAliasTable(metaAliases) {
const lines = [];
lines.push("| Meta-alias | Expands to |");
lines.push("|------------|------------|");
for (const { alias, resolves } of metaAliases) {
const formattedResolves = resolves.map(r => `\`${r}\``).join(" → ");
lines.push(`| \`${alias}\` | ${formattedResolves} |`);
}
return lines.join("\n");
}
function generateMultiplierSection(groupName, rows) {
const lines = [];
lines.push(`### ${groupName}`);
lines.push("");
lines.push("| Model | Multiplier |");
lines.push("|-------|-----------|");
for (const { model, value } of rows) {
lines.push(`| \`${model}\` | ${value} |`);
}
return lines.join("\n");
}
function generateTokenWeightsTable(weights) {
const lines = [];
lines.push("| Token class | Default weight |");
lines.push("|-------------|---------------|");
for (const [cls, weight] of Object.entries(weights)) {
const label = cls.replace(/_/g, " ").replace(/\b\w/g, c => c.toUpperCase());
lines.push(`| ${label} | ${weight} |`);
}
return lines.join("\n");
}
// ---------------------------------------------------------------------------
// Build the full document
// ---------------------------------------------------------------------------
function generateMarkdown() {
const { vendor, meta } = classifyAliases(aliases);
const multiplierGroups = groupMultipliers(multipliers);
const lines = [];
// Frontmatter
lines.push("---");
lines.push("title: Model Aliases & Multipliers");
lines.push("description: Reference tables for the built-in model alias map and per-model Effective Token multipliers used by GitHub Agentic Workflows.");
lines.push("sidebar:");
lines.push(" order: 297");
lines.push("---");
lines.push("");
lines.push("This page lists the built-in model aliases and the per-model Effective Token (ET) multipliers used by GitHub Agentic Workflows.");
lines.push("");
// Approximation callout
lines.push("> [!CAUTION]");
lines.push(
"> The multiplier values shown on this page are **approximations**. They are used solely for the purpose of normalizing token usage across models into a single comparable metric (Effective Tokens) and do **not** represent precise cost ratios. Values may be inaccurate for specific model versions and may become out of date as providers update their offerings. Do not use these numbers for billing or financial calculations."
);
lines.push("");
// -------------------------------------------------------------------------
// Model Aliases
// -------------------------------------------------------------------------
lines.push("## Model Aliases");
lines.push("");
lines.push(
"Model aliases let you write `engine: copilot` with a human-friendly model name such as `sonnet` or `mini`, and gh-aw resolves it to the best available concrete model at compile time. Each alias holds an ordered list of patterns; the first pattern that matches an available model wins."
);
lines.push("");
lines.push("For details on the alias syntax, fallback resolution algorithm, and how to define your own aliases in workflow frontmatter, see the [Model Alias Format Specification](/gh-aw/reference/model-alias-specification/).");
lines.push("");
lines.push("### Vendor Aliases");
lines.push("");
lines.push("Vendor aliases map a short name to one or more provider-scoped glob patterns. The Copilot gateway is always tried first.");
lines.push("");
lines.push(generateAliasTable(vendor));
lines.push("");
lines.push("### Meta-Aliases");
lines.push("");
lines.push("Meta-aliases reference other aliases by name. They are resolved recursively until a concrete pattern is reached.");
lines.push("");
lines.push(generateMetaAliasTable(meta));
lines.push("");
// -------------------------------------------------------------------------
// Model Multipliers
// -------------------------------------------------------------------------
lines.push("## Model Multipliers");
lines.push("");
lines.push(
`Effective Token multipliers scale the weighted token total for each model relative to the reference model (\`${referenceModel}\`, multiplier = 1.0). A multiplier of 5.0 means that a run on that model counts as five times as many Effective Tokens as the same run on the reference model.`
);
lines.push("");
lines.push("See the [Effective Tokens Specification](/gh-aw/reference/effective-tokens-specification/) for the full formula.");
lines.push("");
lines.push("### Token Class Weights");
lines.push("");
lines.push("Before per-model multipliers are applied, raw token counts are weighted by token class:");
lines.push("");
lines.push(generateTokenWeightsTable(tokenClassWeights));
lines.push("");
lines.push("### Per-Model Multipliers");
lines.push("");
for (const [groupName, rows] of Object.entries(multiplierGroups)) {
lines.push(generateMultiplierSection(groupName, rows));
lines.push("");
}
return lines.join("\n");
}
// ---------------------------------------------------------------------------
// Write output
// ---------------------------------------------------------------------------
console.log("Generating model tables documentation...");
const markdown = generateMarkdown();
const outputDir = path.dirname(OUTPUT_PATH);
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
fs.writeFileSync(OUTPUT_PATH, markdown, "utf-8");
console.log(`✓ Generated: ${OUTPUT_PATH}`);