Skip to content
Source
Sign inSign up
TanStack/schemas
Open History to see the last commit

nvidia.test.ts

705 lines19.9 KB

1import { afterEach, describe, expect, it } from 'vitest'
2​
3import { sha256Text } from '../types.ts'
4import { NVIDIA_REFERENCE_INDEXES } from '../nvidia-openapi.ts'
5import { NVIDIA_SITEMAP_URL } from '../nvidia-sitemap.ts'
6import { NVIDIA_MODELS_URL, parseNvidiaCard, provider } from './nvidia.ts'
7​
8/** Excerpt of https://integrate.api.nvidia.com/v1/models (2026-10-06). */
9const LISTING = {
10 object: 'list',
11 data: [
12 {
13 id: '01-ai/yi-large',
14 object: 'model',
15 created: 735790403,
16 owned_by: '01-ai',
17 },
18 {
19 id: 'z-ai/glm-5.3-flash',
20 object: 'model',
21 created: 735790403,
22 owned_by: 'z-ai',
23 },
24 {
25 id: 'google/deplot',
26 object: 'model',
27 created: 735790403,
28 owned_by: 'google',
29 },
30 ],
32​
33const CHAT_PROTOTYPE = (model: string) => `## Prototype
34​
35\`\`\`bash
36curl --fail --show-error --no-buffer https://integrate.api.nvidia.com/v1/chat/completions \\
37-H "Authorization: Bearer $NVIDIA_API_KEY" \\
38--data-binary @- <<'JSON'
40"model": "${model}",
41"messages": [{"role":"user","content":""}]
43JSON
44\`\`\``
45​
46/** Excerpt of https://build.nvidia.com/z-ai/glm-5-3-flash.md (2026-10-06). */
47const GLM_CARD = `---
48title: "glm-5-3-flash"
49publisher: "z-ai"
50type: "endpoint"
51canonical: "https://build.nvidia.com/z-ai/glm-5-3-flash"
52---
53​
54# GLM-5.3-Flash
55​
56## Description
57GLM-5.3-Flash is a multimodal mixture-of-experts model.
58​
59## Specifications
60​
61- **Context Length:** 1,048,576 tokens
62- **Parameters:** 320B
63- **Input:** Text, Image
64- **Output:** Text
65​
66## Capabilities
67​
68- **Function Calling:** Supported
69- **Structured Output:** Supported
70- **Reasoning:** Supported
71​
72${CHAT_PROTOTYPE('z-ai/glm-5.3-flash')}`
73​
74/** Excerpt of https://build.nvidia.com/01-ai/yi-large.md: an older card. */
75const YI_CARD = `---
76title: "yi-large"
77publisher: "01-ai"
78canonical: "https://build.nvidia.com/01-ai/yi-large"
79---
80​
81# Yi-Large
82​
83### Input
84- **Input Type:** Text
85​
86${CHAT_PROTOTYPE('01-ai/yi-large')}`
87​
88/** Excerpt of https://build.nvidia.com/nvidia/embed-qa-4.md. */
89const EMBED_CARD = `# NV-Embed-QA
90​
91## Prototype
92​
93\`\`\`bash
94curl -X POST https://integrate.api.nvidia.com/v1/embeddings \\
95-d '{"input": [""], "model": "nvidia/embed-qa-4"}'
96\`\`\``
97​
98/**
99 * Excerpt of https://build.nvidia.com/nvidia/nemotron-parse.md
100 * (2026-10-06): HTTP 200, text/html, for a card with no markdown twin.
101 */
102const NOT_FOUND_HTML = `<!DOCTYPE html><html id="__next_error__"><head><meta charSet="utf-8"/></head><body><script>self.__next_f.push([1,"2c:E{\\"digest\\":\\"NEXT_HTTP_ERROR_FALLBACK;404\\"}\\n"])</script></body></html>`
103​
104const originalFetch = globalThis.fetch
105​
106afterEach(() => {
107 globalThis.fetch = originalFetch
108})
109​
110const EMPTY_INDEX = '---\nupdatedAt: test\n---\n\n# Index\n'
111​
112function stubFetch(pages: Record<string, string>): Array<string> {
113 const urls: Array<string> = []
114 globalThis.fetch = ((input: string) => {
115 const url = String(input)
116 urls.push(url)
117 const body =
118 pages[url] ??
119 (url.startsWith('https://build.nvidia.com/') &&
120 !url.endsWith('.md') &&
121 pages[`${url}.md`]?.startsWith('---\n')
122 ? '<script>self.__next_f.push([1,"1:{}"])</script>'
123 : undefined) ??
124 (url === NVIDIA_SITEMAP_URL
125 ? '<urlset><url><loc>https://docs.api.nvidia.com/nim/reference/google-gemma-4-31b-it-infer</loc></url></urlset>'
126 : /\/nim\/reference\/[a-z0-9-]+-apis\.md$/.test(url)
127 ? EMPTY_INDEX
128 : undefined)
129 return Promise.resolve(
130 body === undefined
131 ? new Response('Not found', { status: 404 })
132 : new Response(body),
133 )
134 }) as typeof fetch
135 return urls
137​
138describe('parseNvidiaCard', () => {
139 it('reads the Specifications and Capabilities lists', () => {
140 expect(parseNvidiaCard(GLM_CARD)).toEqual({
141 activity: 'chat',
142 contextWindow: 1048576,
143 modalities: { input: ['text', 'image'], output: ['text'] },
144 unsupportedCapabilities: [],
145 capabilities: ['tools', 'structured_outputs', 'reasoning'],
146 })
147 })
148​
149 it('states only the activity for a card without those lists', () => {
150 expect(parseNvidiaCard(YI_CARD)).toEqual({ activity: 'chat' })
151 })
152​
153 it('reads an embeddings prototype and leaves other routes null', () => {
154 expect(parseNvidiaCard(EMBED_CARD)).toEqual({ activity: 'embeddings' })
155 expect(parseNvidiaCard('# Card\n\n## Prototype\n\nnone')).toEqual({
156 activity: null,
157 })
158 })
159​
160 it('reads older labeled input and output lines', () => {
161 const card = `# Yi
162​
163## Input
164​
165- Input Type: Text
166- Context length: 32k
167​
168## Output
169​
170- Output Type: Text and Code
171​
172${CHAT_PROTOTYPE('01-ai/yi-large')}`
173 expect(parseNvidiaCard(card)).toEqual({
174 activity: 'chat',
175 contextWindow: 32000,
176 modalities: { input: ['text'], output: ['text'] },
177 })
178 })
179​
180 it('reads a labeled max output and prefers the Specifications context', () => {
181 const card = `# Jamba
182​
183## Input:
184**Max Input Tokens:** 256,000 <br>
185​
186## Output:
187**Output Type:** Text <br>
188**Max Output Tokens:** 256,000 <br>
189​
190## Specifications
191​
192- **Context Length:** 262,144 tokens
193- **Input:** Text
194- **Output:** Text
196 expect(parseNvidiaCard(card)).toMatchObject({
197 contextWindow: 262144,
198 maxOutput: 256000,
199 modalities: { input: ['text'], output: ['text'] },
200 })
201 })
202​
203 it('does not take an output modality from a mislabeled section', () => {
204 const card = `# gemma
205​
206## Input:
207**Input Type(s):** Text <br>
208​
209## Output:
210**Input Type(s):** Text <br>
211​
212${CHAT_PROTOTYPE('google/gemma-2b')}`
213 expect(parseNvidiaCard(card).modalities).toBeUndefined()
214 expect(parseNvidiaCard(card).activity).toBe('chat')
215 })
216​
217 it('reads bold Input and Output blocks and a pure format cell', () => {
218 const bold = `# SEA-LION
219​
220**Input**
221* Input Type: Text
222* Input Format: String
223​
224**Output**
225* Output Type: Text
226* Output Format: String
228 expect(parseNvidiaCard(bold).modalities).toEqual({
229 input: ['text'],
230 output: ['text'],
231 })
232 const format = `# StarCoder
233​
234## Input:
235**Input Format:** Text <br>
236​
237## Output:
238**Output Format:** Text (code) <br>
240 expect(parseNvidiaCard(format).modalities).toEqual({
241 input: ['text'],
242 output: ['text'],
243 })
244 const stringFormat = `# Granite
245​
246**Input**
247* Input Format: String
248​
249**Output**
250* Output Format: String
252 expect(parseNvidiaCard(stringFormat).modalities).toBeUndefined()
253 })
254​
255 it('reads a context length of up to N outside the Input section', () => {
256 const card = `# Gemma
257​
258Gemma models support a context length of up to 8K while using RoPE.
260 expect(parseNvidiaCard(card).contextWindow).toBe(8000)
261 })
262​
263 it('classifies a completions route and a VLM messages route as chat', () => {
264 expect(
265 parseNvidiaCard(`## Prototype
266​
267invoke_url='https://integrate.api.nvidia.com/v1/completions'
268`).activity,
269 ).toBe('chat')
270 expect(
271 parseNvidiaCard(`## Prototype
272​
273invoke_url = "https://ai.api.nvidia.com/v1/vlm/adept/fuyu-8b"
274payload = {"messages": [{"role": "user", "content": ""}]}
275`).activity,
276 ).toBe('chat')
277 })
278​
279 it('classifies an embedding card that names floats and no prototype URL', () => {
280 const card = `---
281description: "1B embedding model for semantic search."
282---
283​
284## Output(s):
285​
286**Output Type(s):** Floats <br>
287​
288## Specifications
289​
290- **Context Length:** 32,768 tokens
292 expect(parseNvidiaCard(card)).toMatchObject({
293 activity: 'embeddings',
294 contextWindow: 32768,
295 })
296 expect(parseNvidiaCard(card).modalities).toBeUndefined()
297 })
298​
299 it('reads an enable_thinking table as a toggle that can be off', () => {
300 const card = `# Nemotron
301​
302| **Reasoning Mode** | Configurable on/off via chat template (\`enable_thinking=True/False\`) |
304 expect(parseNvidiaCard(card).reasoning).toEqual({
305 mode: 'toggle',
306 mandatory: false,
307 })
308 })
309​
310 it('reads a reasoning_effort list and an always-on sentence', () => {
311 expect(
312 parseNvidiaCard(
313 'Thinking budget is controlled by `reasoning_effort`, which accepts `none`, `low`, or `high` and defaults to `high`.',
314 ).reasoning?.mandatory,
315 ).toBeNull()
316 expect(
317 parseNvidiaCard(
318 'Thinking budget is controlled by `reasoning_effort`, which accepts `low`,\n`high`, or `max` and defaults to `max`.',
319 ).reasoning,
320 ).toEqual({
321 mode: 'effort',
322 mandatory: null,
323 efforts: ['low', 'high', 'max'],
324 })
325 expect(
326 parseNvidiaCard(
327 '**Other Output Properties:** configurable low, high, or max reasoning effort. Thinking is always enabled.',
328 ).reasoning,
329 ).toEqual({
330 mode: 'effort',
331 mandatory: true,
332 efforts: ['low', 'high', 'max'],
333 })
334 expect(
335 parseNvidiaCard(
336 '- **Configurable reasoning effort:** Easily adjust the reasoning effort (low, medium, high) based on latency.',
337 ).reasoning,
338 ).toEqual({
339 mode: 'effort',
340 mandatory: null,
341 efforts: ['low', 'medium', 'high'],
342 })
343 })
344​
345 it('does not invent a reasoning object from prose that names no request field', () => {
346 const card = `supported reasoning-strength settings are low, medium, high, and xhigh.
347Use the prompt token <|think|>.
348numeric reasoning effort from 1 to 100.
349​
350## Capabilities
351​
352- **Reasoning:** Supported
354 const facts = parseNvidiaCard(card)
355 expect(facts.reasoning).toBeUndefined()
356 expect(facts.capabilities).toEqual(['reasoning'])
357 expect(facts.exactCapabilities).toBeUndefined()
358 expect(facts.unsupportedCapabilities).toEqual([])
359 })
360})
361​
362describe('nvidia', () => {
363 it('joins listed ids to their cards and leaves prices null', async () => {
364 const urls = stubFetch({
365 [NVIDIA_MODELS_URL]: JSON.stringify(LISTING),
366 'https://build.nvidia.com/01-ai/yi-large.md': YI_CARD,
367 'https://build.nvidia.com/z-ai/glm-5-3-flash.md': GLM_CARD,
368 })
369​
370 const listed = await provider.listModels({})
371 await expect(provider.fetchSpec({})).rejects.toThrow(
372 'parsed 0 generation specs',
373 )
374​
375 const source = {
376 derivation: 'docs-derived',
377 sourceUrl: 'https://build.nvidia.com/z-ai/glm-5-3-flash',
378 sourceHash: await sha256Text(GLM_CARD),
379 }
380 expect(listed.models).toEqual([
381 {
382 rawId: '01-ai/yi-large',
383 releasedAt: 735790403,
384 pricing: null,
385 requestMap: null,
386 activity: 'chat',
387 factSources: {},
388 },
389 {
390 rawId: 'z-ai/glm-5.3-flash',
391 releasedAt: 735790403,
392 pricing: null,
393 requestMap: null,
394 activity: 'chat',
395 contextWindow: 1048576,
396 modalities: { input: ['text', 'image'], output: ['text'] },
397 unsupportedCapabilities: [],
398 capabilities: ['tools', 'structured_outputs', 'reasoning'],
399 factSources: {
400 contextWindow: { ...source, path: 'contextWindow' },
401 modalities: { ...source, path: 'modalities' },
402 capabilities: {
403 tools: { ...source, path: 'capabilities.tools' },
404 structured_outputs: {
405 ...source,
406 path: 'capabilities.structured_outputs',
407 },
408 reasoning: { ...source, path: 'capabilities.reasoning' },
409 },
410 },
411 },
412 // No card under any slug: listed, no facts.
413 {
414 rawId: 'google/deplot',
415 releasedAt: 735790403,
416 pricing: null,
417 requestMap: null,
418 },
419 ])
420 expect(urls).toContain('https://build.nvidia.com/z-ai/glm-5_3-flash.md')
421 })
422​
423 it('throws when no card names a route', async () => {
424 stubFetch({ [NVIDIA_MODELS_URL]: JSON.stringify(LISTING) })
425 await expect(provider.listModels({})).rejects.toThrow(
426 'nvidia model cards: parsed 0 model rows',
427 )
428 })
429​
430 it('lists the ids and reports the cards when every card fails to load', async () => {
431 globalThis.fetch = ((input: string) =>
432 Promise.resolve(
433 String(input) === NVIDIA_MODELS_URL
434 ? new Response(JSON.stringify(LISTING))
435 : new Response('busy', { status: 503 }),
436 )) as typeof fetch
437 const listed = await provider.listModels({})
438 expect(listed.models).toHaveLength(LISTING.data.length)
439 expect(listed.docsFailures).toMatchObject({
440 failed: LISTING.data.length + NVIDIA_REFERENCE_INDEXES.length + 1,
441 skipped: 0,
442 })
443 expect(listed.docsFailures?.first[0]?.error).toContain('503')
444 for (const model of listed.models) {
445 expect(model.absent).toEqual({
446 activity: 'unavailable',
447 contextWindow: 'unavailable',
448 maxOutput: 'unavailable',
449 modalities: 'unavailable',
450 capabilities: 'unavailable',
451 reasoning: 'unavailable',
452 schemaEndpointId: 'unavailable',
453 })
454 }
455 })
456​
457 const cards = (deplot: string) => ({
458 [NVIDIA_MODELS_URL]: JSON.stringify(LISTING),
459 'https://build.nvidia.com/01-ai/yi-large.md': YI_CARD,
460 'https://build.nvidia.com/google/deplot.md': deplot,
461 })
462​
463 it('reads the HTML not-found page served with 200 as no card', async () => {
464 stubFetch(cards(NOT_FOUND_HTML))
465 const listed = await provider.listModels({})
466 expect(listed.models.find((m) => m.rawId === 'google/deplot')).toEqual({
467 rawId: 'google/deplot',
468 releasedAt: 735790403,
469 pricing: null,
470 requestMap: null,
471 })
472 })
473​
474 it('keeps the other cards when one body is not a markdown card', async () => {
475 stubFetch(cards('<!DOCTYPE html><html><body>Just a moment</body></html>'))
476 const listed = await provider.listModels({})
477 expect(listed.docsFailures?.first).toMatchObject([
478 {
479 source: 'https://build.nvidia.com/google/deplot.md',
480 error:
481 'nvidia: https://build.nvidia.com/google/deplot.md is not a markdown card',
482 },
483 ])
484 const byId = new Map(listed.models.map((m) => [m.rawId, m]))
485 expect(byId.get('01-ai/yi-large')).toMatchObject({ activity: 'chat' })
486 expect(byId.get('01-ai/yi-large')?.absent).toBeUndefined()
487 expect(byId.get('google/deplot')?.absent).toMatchObject({
488 activity: 'unavailable',
489 })
490 })
491​
492 it('ignores a card whose canonical URL is another page', async () => {
493 stubFetch(cards(YI_CARD))
494 const listed = await provider.listModels({})
495 expect(
496 listed.models.find((m) => m.rawId === 'google/deplot')?.activity,
497 ).toBeUndefined()
498 })
499​
500 it('fills max output, reasoning, and the endpoint from that model OpenAPI', async () => {
501 const infer =
502 'https://docs.api.nvidia.com/nim/reference/z-ai-glm-5-3-flash-infer'
503 const openapi = `# OpenAPI definition
504​
505\`\`\`json
507 "openapi": "3.1.0",
508 "paths": {
509 "/chat/completions": {
510 "post": {
511 "requestBody": {
512 "content": {
513 "application/json": {
514 "schema": {
515 "type": "object",
516 "properties": {
517 "max_tokens": {
518 "type": "integer",
519 "maximum": 8192,
520 "minimum": 1,
521 "description": "The maximum number of tokens to generate."
522 },
523 "model": { "type": "string", "default": "z-ai/glm-5.3-flash" },
524 "reasoning_effort": { "type": "string", "enum": ["none", "high"] }
525 }
526 }
527 }
528 }
529 }
530 }
531 }
532 }
534\`\`\`
536 stubFetch({
537 [NVIDIA_MODELS_URL]: JSON.stringify(LISTING),
538 'https://build.nvidia.com/z-ai/glm-5-3-flash.md': GLM_CARD,
539 'https://build.nvidia.com/01-ai/yi-large.md': YI_CARD,
540 [NVIDIA_REFERENCE_INDEXES[0]!]: `---
541updatedAt: test
542---
543​
544| Model | Endpoint |
545| --- | --- |
546| [z-ai / glm-5.3-flash](https://docs.api.nvidia.com/nim/reference/z-ai-glm-5-3-flash) | [chat](${infer}) |
547`,
548 [`${infer}.md`]: openapi,
549 })
550 const listed = await provider.listModels({})
551 const glm = listed.models.find(
552 (model) => model.rawId === 'z-ai/glm-5.3-flash',
553 )
554 expect(glm).toMatchObject({
555 maxOutput: 8192,
556 reasoning: {
557 mode: 'effort',
558 mandatory: null,
559 efforts: ['none', 'high'],
560 },
561 schemaEndpointId: 'z-ai/glm-5.3-flash',
562 })
563 expect(glm?.factSources?.maxOutput).toMatchObject({
564 sourceUrl: infer + '.md',
565 path: 'max_tokens',
566 })
567 expect(glm?.factSources?.contextWindow?.sourceUrl).toBe(
568 'https://build.nvidia.com/z-ai/glm-5-3-flash',
569 )
570 const spec = await provider.fetchSpec({})
571 expect(spec.skipped).toBeUndefined()
572 expect(spec.specs).toEqual([])
573 expect(spec.bundledEndpoints).toHaveLength(1)
574 expect(spec.bundledEndpoints?.[0]).toMatchObject({
575 publicId: 'z-ai/glm-5.3-flash',
576 path: '/chat/completions',
577 })
578 expect(
579 provider.classify('/z-ai/glm-5.3-flash', {
580 'x-modelschemas-activity': 'chat',
581 }),
582 ).toBe('chat')
583 })
584​
585 it('does not copy an infer document that names a different model', async () => {
586 const infer =
587 'https://docs.api.nvidia.com/nim/reference/nvidia-nemotron-3-5-content-safety-infer'
588 const openapi = `# OpenAPI definition
589​
590\`\`\`json
592 "openapi": "3.1.0",
593 "info": { "title": "nvidia/nemotron-3-nano-omni-30b-a3b-reasoning" },
594 "paths": {
595 "/chat/completions": {
596 "post": {
597 "requestBody": {
598 "content": {
599 "application/json": {
600 "schema": {
601 "type": "object",
602 "properties": {
603 "model": {
604 "type": "string",
605 "default": "nvidia/nemotron-3-nano-omni-30b-a3b-reasoning"
606 },
607 "max_tokens": {
608 "type": "integer",
609 "maximum": 65536,
610 "description": "The maximum number of tokens to generate."
611 },
612 "reasoning_budget": { "type": "integer", "maximum": 32768 }
613 }
614 }
615 }
616 }
617 }
618 }
619 }
620 }
622\`\`\`
624 stubFetch({
625 [NVIDIA_MODELS_URL]: JSON.stringify({
626 object: 'list',
627 data: [
628 {
629 id: 'nvidia/nemotron-3.5-content-safety',
630 object: 'model',
631 created: 735790403,
632 owned_by: 'nvidia',
633 },
634 ],
635 }),
636 'https://build.nvidia.com/nvidia/nemotron-3.5-content-safety.md': `---
637title: "nemotron-3.5-content-safety"
638canonical: "https://build.nvidia.com/nvidia/nemotron-3.5-content-safety"
639---
640​
641## Specifications
642​
643- **Context Length:** 131,072 tokens
644- **Input:** Text
645- **Output:** Text
646​
647## Capabilities
648​
649- **Reasoning:** Supported
650​
651${CHAT_PROTOTYPE('nvidia/nemotron-3.5-content-safety')}`,
652 [NVIDIA_REFERENCE_INDEXES[0]!]: `---
653updatedAt: test
654---
655​
656| Model | Endpoint |
657| --- | --- |
658| [nvidia / nemotron-3.5-content-safety](https://docs.api.nvidia.com/nim/reference/nvidia-nemotron-3-5-content-safety) | [chat](${infer}) |
659`,
660 [`${infer}.md`]: openapi,
661 })
662 const listed = await provider.listModels({})
663 const safety = listed.models.find(
664 (model) => model.rawId === 'nvidia/nemotron-3.5-content-safety',
665 )
666 expect(safety?.maxOutput).toBeUndefined()
667 expect(safety?.reasoning).toBeUndefined()
668 expect(safety?.schemaEndpointId).toBeUndefined()
669 expect(safety?.contextWindow).toBe(131072)
670 await expect(provider.fetchSpec({})).rejects.toThrow(
671 'parsed 0 generation specs',
672 )
673 })
674})
675​
676it('reads hosted replay instructions rather than copying maker behavior', () => {
677 const card =
678 '# Native card\n\n## Prototype\nPOST /v1/chat/completions\n\nClients must pass back the complete assistant message, including reasoning_content and tool_calls.'
679 expect(parseNvidiaCard(card).requestMap?.replayReasoningContent).toBe(true)
680 expect(
681 parseNvidiaCard(
682 card.replace(
683 'must pass back the complete assistant message, including',
684 'returns',
685 ),
686 ).requestMap,
687 ).toBeUndefined()
688})
689​
690it('does not make card reasoning mandatory from negated or fenced always-enabled prose', () => {
691 const effort = '**Configurable reasoning effort:** levels (`low`, `high`)'
692 for (const phrase of [
693 'Do not assume thinking is always enabled.',
694 'Never assume thinking is always enabled.',
695 '```text\nThinking is always enabled.\n```',
696 ]) {
697 expect(
698 parseNvidiaCard(effort + '\n' + phrase).reasoning?.mandatory,
699 ).toBeNull()
700 }
701 expect(
702 parseNvidiaCard(effort + '\nThinking is always enabled.').reasoning
703 ?.mandatory,
704 ).toBe(true)
705})