Repository navigation
feat(models): add per-provider model manifests as a single metadata source #1351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| #!/usr/bin/env npx tsx | ||
| /** | ||
| * One-time generator for the 28 model manifests not hand-authored in Tasks | ||
| * 2-3. Reads only exported symbols from the pre-migration model-metadata | ||
| * stores (MODEL_REGISTRY, getContextWindowSize, ProviderImageAdapter, | ||
| * PROVIDER_MAX_TOKENS) — see Task 5's design note for why the private | ||
| * PRICING/VISION_CAPABILITIES tables aren't imported directly. Run once; | ||
| * the output files are committed and hand-editable afterward like Tasks 2-3. | ||
| * | ||
| * calculateCost is imported from utils/pricing.js, NOT models/modelRegistry.js | ||
| * — both modules export a same-named function, but only pricing.ts's version | ||
| * is the actual cost calculator that reads the PRICING table hasPricing() | ||
| * gates on. Reading modelRegistry.js's calculateCost here would read a | ||
| * different store than the one hasPricing() just checked, producing | ||
| * internally-inconsistent data in exactly the cases the gate exists to catch. | ||
| */ | ||
| import { writeFileSync } from "node:fs"; | ||
| import { AIProviderName } from "../src/lib/constants/enums.js"; | ||
| import { getModelsByProvider } from "../src/lib/models/modelRegistry.js"; | ||
| import { calculateCost, hasPricing } from "../src/lib/utils/pricing.js"; | ||
| import { getContextWindowSize } from "../src/lib/constants/contextWindows.js"; | ||
| import { ProviderImageAdapter } from "../src/lib/adapters/providerImageAdapter.js"; | ||
| import { PROVIDER_MAX_TOKENS } from "../src/lib/core/constants.js"; | ||
|
|
||
| const FULL_PROVIDERS = [ | ||
| AIProviderName.AZURE, | ||
| AIProviderName.BEDROCK, | ||
| AIProviderName.OLLAMA, | ||
| AIProviderName.MISTRAL, | ||
| AIProviderName.GOOGLE_AI, | ||
| ] as const; | ||
|
|
||
| const MINIMAL_PROVIDERS = [ | ||
| AIProviderName.OPENAI_COMPATIBLE, | ||
| AIProviderName.OPENROUTER, | ||
| AIProviderName.VERTEX, | ||
| AIProviderName.HUGGINGFACE, | ||
| AIProviderName.LITELLM, | ||
| AIProviderName.SAGEMAKER, | ||
| AIProviderName.DEEPSEEK, | ||
| AIProviderName.NVIDIA_NIM, | ||
| AIProviderName.LM_STUDIO, | ||
| AIProviderName.LLAMACPP, | ||
| AIProviderName.XAI, | ||
| AIProviderName.GROQ, | ||
| AIProviderName.COHERE, | ||
| AIProviderName.TOGETHER_AI, | ||
| AIProviderName.FIREWORKS, | ||
| AIProviderName.PERPLEXITY, | ||
| AIProviderName.CLOUDFLARE, | ||
| AIProviderName.REPLICATE, | ||
| AIProviderName.VOYAGE, | ||
| AIProviderName.JINA, | ||
| AIProviderName.STABILITY, | ||
| AIProviderName.IDEOGRAM, | ||
| AIProviderName.RECRAFT, | ||
| ] as const; | ||
|
|
||
| function toCamel(provider: string): string { | ||
| return provider.replace(/-([a-z])/g, (_, c: string) => c.toUpperCase()); | ||
| } | ||
|
|
||
| function quoteKey(key: string): string { | ||
| return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key) ? key : JSON.stringify(key); | ||
| } | ||
|
|
||
| function generateFullManifest(provider: AIProviderName): string { | ||
| const models = getModelsByProvider(provider); | ||
| const entries = models | ||
| .map((m) => { | ||
| const priced = hasPricing(provider, m.id); | ||
| // usage.total is required by TokenUsage's type but unused by | ||
| // calculateCost's body (src/lib/utils/pricing.ts:750-779) — it only | ||
| // reads .input/.output/.cacheReadTokens/.cacheCreationTokens. Probing | ||
| // with 1_000_000 units on one side and 0 on the other isolates each | ||
| // per-token rate scaled back up to a per-million-token price. | ||
| const inputRate = priced | ||
| ? calculateCost(provider, m.id, { | ||
| input: 1_000_000, | ||
| output: 0, | ||
| total: 1_000_000, | ||
| }) | ||
| : undefined; | ||
| const outputRate = priced | ||
| ? calculateCost(provider, m.id, { | ||
| input: 0, | ||
| output: 1_000_000, | ||
| total: 1_000_000, | ||
| }) | ||
| : undefined; | ||
| const pricing = | ||
| priced && inputRate !== undefined && outputRate !== undefined | ||
| ? `{ input: ${inputRate}, output: ${outputRate} }` | ||
| : undefined; | ||
| const vision = ProviderImageAdapter.supportsVision(provider, m.id); | ||
| return ` ${quoteKey(m.id)}: { | ||
| aliases: ${JSON.stringify(m.aliases)}, | ||
| displayName: ${JSON.stringify(m.name)}, | ||
| contextWindow: ${m.limits.maxContextTokens}, | ||
| maxOutputTokens: ${m.limits.maxOutputTokens}, | ||
| ${pricing ? `pricingPerMTok: ${pricing},` : "// pricingPerMTok omitted: hasPricing() reports no verified rate"} | ||
| vision: ${vision}, | ||
| functionCalling: ${m.capabilities.functionCalling}, | ||
| reasoning: ${m.capabilities.reasoning}, | ||
| jsonMode: ${m.capabilities.jsonMode}, | ||
| },`; | ||
| }) | ||
| .join("\n"); | ||
| const defaultWindow = getContextWindowSize(provider); | ||
| return `import type { ProviderModelManifest } from "../../types/index.js"; | ||
|
|
||
| export const ${toCamel(provider)}Manifest: ProviderModelManifest = { | ||
| defaultContextWindow: ${defaultWindow}, | ||
| models: { | ||
| ${entries} | ||
| }, | ||
| }; | ||
| `; | ||
| } | ||
|
|
||
| function generateMinimalManifest(provider: AIProviderName): string { | ||
| const defaultWindow = getContextWindowSize(provider); | ||
| const providerLimits = PROVIDER_MAX_TOKENS[ | ||
| provider as keyof typeof PROVIDER_MAX_TOKENS | ||
| ] as { default?: number } | number | undefined; | ||
| const rawMaxOutput = | ||
| typeof providerLimits === "number" | ||
| ? providerLimits | ||
| : (providerLimits?.default ?? PROVIDER_MAX_TOKENS.default); | ||
| // An output ceiling can never legitimately exceed total context — most | ||
| // MINIMAL_PROVIDERS aren't in PROVIDER_MAX_TOKENS's explicit 9-provider | ||
| // list, so they fall to its flat 64000 default regardless of how small | ||
| // their real context window is. Clamp rather than let the two diverge. | ||
| const maxOutput = Math.min(rawMaxOutput, defaultWindow); | ||
| return `import type { ProviderModelManifest } from "../../types/index.js"; | ||
|
|
||
| /** | ||
| * Minimal manifest: ${provider} has no MODEL_REGISTRY entries today, so | ||
| * only the provider-wide fallback is known. Named models can be added here | ||
| * incrementally without touching any consumer — see Task 5 of the model | ||
| * metadata consolidation plan. | ||
| */ | ||
| export const ${toCamel(provider)}Manifest: ProviderModelManifest = { | ||
| defaultContextWindow: ${defaultWindow}, | ||
| models: { | ||
| _default: { | ||
| aliases: [], | ||
| contextWindow: ${defaultWindow}, | ||
| maxOutputTokens: ${maxOutput}, | ||
| vision: false, | ||
| functionCalling: false, | ||
| }, | ||
| }, | ||
| }; | ||
| `; | ||
| } | ||
|
|
||
| for (const provider of FULL_PROVIDERS) { | ||
| writeFileSync( | ||
| `src/lib/models/manifests/${provider}.ts`, | ||
| generateFullManifest(provider), | ||
| ); | ||
| console.log(`wrote src/lib/models/manifests/${provider}.ts`); | ||
| } | ||
|
|
||
| for (const provider of MINIMAL_PROVIDERS) { | ||
| writeFileSync( | ||
| `src/lib/models/manifests/${provider}.ts`, | ||
| generateMinimalManifest(provider), | ||
| ); | ||
| console.log(`wrote src/lib/models/manifests/${provider}.ts`); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Generate the SageMaker manifest from registered models.
The PR stack defines
src/lib/models/manifests/sagemaker.tsas a curated manifest with named model metadata. Line 39 generates it as a minimal manifest instead. Running this script overwrites its named models, aliases, capabilities, limits, and pricing.Move
AIProviderName.SAGEMAKERtoFULL_PROVIDERS.Proposed fix
Also applies to: 39-39
🤖 Prompt for AI Agents