-
Notifications
You must be signed in to change notification settings - Fork 3.1k
docs: add inference model task-fit guide #5527
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
Show all changes
7 commits
Select commit
Hold shift + click to select a range
21b7bf2
docs: add inference model task-fit guide
HOYALIM 7ddf296
test: document inference docs helpers
HOYALIM fd4e480
test: use block docstrings for inference docs helpers
HOYALIM d5309ba
docs: address task-fit guide review feedback
HOYALIM e772e8d
Update test/inference-options-docs.test.ts
miyoungc cd46d8d
Update test/inference-options-docs.test.ts
miyoungc 137896c
Merge branch 'main' into codex/issue-4755-task-fit-docs
miyoungc 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,128 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import fs from "node:fs"; | ||
| import { createRequire } from "node:module"; | ||
| import path from "node:path"; | ||
| import { fileURLToPath } from "node:url"; | ||
| import type * as TypeScript from "typescript"; | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| const require = createRequire(import.meta.url); | ||
| const ts = require("typescript") as typeof TypeScript; | ||
| const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); | ||
| const inferenceOptionsPath = path.join(repoRoot, "docs", "inference", "inference-options.mdx"); | ||
| const inferenceConfigPath = path.join(repoRoot, "src", "lib", "inference", "config.ts"); | ||
| const modelPromptsPath = path.join(repoRoot, "src", "lib", "inference", "model-prompts.ts"); | ||
|
|
||
| /** | ||
| * Removes TypeScript `as const` wrappers before inspecting literal AST nodes. | ||
| */ | ||
| function unwrapConstAssertion(expression: TypeScript.Expression): TypeScript.Expression { | ||
| return ts.isAsExpression(expression) ? unwrapConstAssertion(expression.expression) : expression; | ||
| } | ||
|
|
||
| function readExportedConstInitializer( | ||
| sourcePath: string, | ||
| exportName: string, | ||
| ): { sourceFile: TypeScript.SourceFile; initializer: TypeScript.Expression } { | ||
| const source = fs.readFileSync(sourcePath, "utf8"); | ||
| const sourceFile = ts.createSourceFile(sourcePath, source, ts.ScriptTarget.Latest, true); | ||
|
|
||
| const declaration = sourceFile.statements | ||
| .filter( | ||
| (statement): statement is TypeScript.VariableStatement => | ||
| ts.isVariableStatement(statement) && | ||
| (statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword) ?? | ||
| false), | ||
| ) | ||
| .flatMap((statement) => Array.from(statement.declarationList.declarations)) | ||
| .find((candidate) => candidate.name.getText(sourceFile) === exportName); | ||
| expect(declaration).toBeTruthy(); | ||
|
|
||
| const initializer = declaration?.initializer && unwrapConstAssertion(declaration.initializer); | ||
| expect(initializer).toBeTruthy(); | ||
|
|
||
| return { sourceFile, initializer: initializer as TypeScript.Expression }; | ||
| } | ||
|
|
||
| function readCuratedCloudModelIds(): string[] { | ||
| const { sourceFile, initializer } = readExportedConstInitializer( | ||
| inferenceConfigPath, | ||
| "CLOUD_MODEL_OPTIONS", | ||
| ); | ||
| expect(ts.isArrayLiteralExpression(initializer)).toBe(true); | ||
|
|
||
| return (initializer as TypeScript.ArrayLiteralExpression).elements.map((element) => { | ||
| expect(ts.isObjectLiteralExpression(element)).toBe(true); | ||
| const idProperty = (element as TypeScript.ObjectLiteralExpression).properties.find( | ||
| (property) => | ||
| ts.isPropertyAssignment(property) && | ||
| property.name.getText(sourceFile) === "id" && | ||
| ts.isStringLiteralLike(unwrapConstAssertion(property.initializer)), | ||
| ); | ||
| expect(idProperty).toBeTruthy(); | ||
| const idInitializer = unwrapConstAssertion( | ||
| (idProperty as TypeScript.PropertyAssignment).initializer, | ||
| ); | ||
| return (idInitializer as TypeScript.StringLiteral).text; | ||
| }); | ||
| } | ||
|
|
||
| function readRemoteModelIds(providerKey: string): string[] { | ||
| const { sourceFile, initializer } = readExportedConstInitializer( | ||
| modelPromptsPath, | ||
| "REMOTE_MODEL_OPTIONS", | ||
| ); | ||
| expect(ts.isObjectLiteralExpression(initializer)).toBe(true); | ||
|
|
||
| const providerProperty = (initializer as TypeScript.ObjectLiteralExpression).properties.find( | ||
| (property) => | ||
| ts.isPropertyAssignment(property) && property.name.getText(sourceFile) === providerKey, | ||
| ); | ||
| expect(providerProperty).toBeTruthy(); | ||
|
|
||
| const providerInitializer = unwrapConstAssertion( | ||
| (providerProperty as TypeScript.PropertyAssignment).initializer, | ||
| ); | ||
| expect(ts.isArrayLiteralExpression(providerInitializer)).toBe(true); | ||
|
|
||
| return (providerInitializer as TypeScript.ArrayLiteralExpression).elements.map((element) => { | ||
| expect(ts.isStringLiteralLike(unwrapConstAssertion(element))).toBe(true); | ||
| return (unwrapConstAssertion(element) as TypeScript.StringLiteral).text; | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Reads curated onboarding model IDs from source config instead of duplicating them in docs tests. | ||
| */ | ||
| function readCuratedOnboardingModelIds(): string[] { | ||
| return [ | ||
| ...readCuratedCloudModelIds(), | ||
| ...readRemoteModelIds("openai"), | ||
| ...readRemoteModelIds("anthropic"), | ||
| ...readRemoteModelIds("gemini"), | ||
| ]; | ||
| } | ||
|
|
||
| describe("inference options model task-fit docs (#4755)", () => { | ||
| it("keeps a per-model task-fit comparison table for curated onboarding models", () => { | ||
| const markdown = fs.readFileSync(inferenceOptionsPath, "utf8"); | ||
| const start = markdown.indexOf("## Model Task-Fit Guide"); | ||
| const end = markdown.indexOf("## Choosing the Right Option for Nemotron", start); | ||
| expect(start).toBeGreaterThanOrEqual(0); | ||
| expect(end).toBeGreaterThan(start); | ||
| const section = markdown.slice(start, end); | ||
|
|
||
| expect(section).toContain( | ||
| "| Model | Best-for task type | Relative latency | Tool-use quality | Context-window fit | Relative cost |", | ||
| ); | ||
| expect(section).toContain("provider catalog remains authoritative"); | ||
| expect(section).not.toMatch(/\bTBD\b|\bTODO\b/i); | ||
| expect(section).not.toContain("Very large context"); | ||
|
|
||
| for (const modelId of readCuratedOnboardingModelIds()) { | ||
| expect(section).toContain(`| \`${modelId}\` |`); | ||
| } | ||
| }); | ||
| }); | ||
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.
Uh oh!
There was an error while loading. Please reload this page.