Open History to see the last commit
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 ],
31}
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'
39{
40"model": "${model}",
41"messages": [{"role":"user","content":""}]
42}
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 === NVIDIA_SITEMAP_URL
120 ? '<urlset><url><loc>https://docs.api.nvidia.com/nim/reference/google-gemma-4-31b-it-infer</loc></url></urlset>'
121 : /\/nim\/reference\/[a-z0-9-]+-apis\.md$/.test(url)
122 ? EMPTY_INDEX
123 : undefined)
124 return Promise.resolve(
125 body === undefined
126 ? new Response('Not found', { status: 404 })
127 : new Response(body),
128 )
129 }) as typeof fetch
130 return urls
131}
132
133describe('parseNvidiaCard', () => {
134 it('reads the Specifications and Capabilities lists', () => {
135 expect(parseNvidiaCard(GLM_CARD)).toEqual({
136 activity: 'chat',
137 contextWindow: 1048576,
138 modalities: { input: ['text', 'image'], output: ['text'] },
139 exactCapabilities: true,
140 capabilities: ['tools', 'structured_outputs', 'reasoning'],
141 })
142 })
143
144 it('states only the activity for a card without those lists', () => {
145 expect(parseNvidiaCard(YI_CARD)).toEqual({ activity: 'chat' })
146 })
147
148 it('reads an embeddings prototype and leaves other routes null', () => {
149 expect(parseNvidiaCard(EMBED_CARD)).toEqual({ activity: 'embeddings' })
150 expect(parseNvidiaCard('# Card\n\n## Prototype\n\nnone')).toEqual({
151 activity: null,
152 })
153 })
154
155 it('reads older labeled input and output lines', () => {
156 const card = `# Yi
157
158## Input
159
160- Input Type: Text
161- Context length: 32k
162
163## Output
164
165- Output Type: Text and Code
166
167${CHAT_PROTOTYPE('01-ai/yi-large')}`
168 expect(parseNvidiaCard(card)).toEqual({
169 activity: 'chat',
170 contextWindow: 32000,
171 modalities: { input: ['text'], output: ['text'] },
172 })
173 })
174
175 it('reads a labeled max output and prefers the Specifications context', () => {
176 const card = `# Jamba
177
178## Input:
179**Max Input Tokens:** 256,000 <br>
180
181## Output:
182**Output Type:** Text <br>
183**Max Output Tokens:** 256,000 <br>
184
185## Specifications
186
187- **Context Length:** 262,144 tokens
188- **Input:** Text
189- **Output:** Text
190`
191 expect(parseNvidiaCard(card)).toMatchObject({
192 contextWindow: 262144,
193 maxOutput: 256000,
194 modalities: { input: ['text'], output: ['text'] },
195 })
196 })
197
198 it('does not take an output modality from a mislabeled section', () => {
199 const card = `# gemma
200
201## Input:
202**Input Type(s):** Text <br>
203
204## Output:
205**Input Type(s):** Text <br>
206
207${CHAT_PROTOTYPE('google/gemma-2b')}`
208 expect(parseNvidiaCard(card).modalities).toBeUndefined()
209 expect(parseNvidiaCard(card).activity).toBe('chat')
210 })
211
212 it('reads bold Input and Output blocks and a pure format cell', () => {
213 const bold = `# SEA-LION
214
215**Input**
216* Input Type: Text
217* Input Format: String
218
219**Output**
220* Output Type: Text
221* Output Format: String
222`
223 expect(parseNvidiaCard(bold).modalities).toEqual({
224 input: ['text'],
225 output: ['text'],
226 })
227 const format = `# StarCoder
228
229## Input:
230**Input Format:** Text <br>
231
232## Output:
233**Output Format:** Text (code) <br>
234`
235 expect(parseNvidiaCard(format).modalities).toEqual({
236 input: ['text'],
237 output: ['text'],
238 })
239 const stringFormat = `# Granite
240
241**Input**
242* Input Format: String
243
244**Output**
245* Output Format: String
246`
247 expect(parseNvidiaCard(stringFormat).modalities).toBeUndefined()
248 })
249
250 it('reads a context length of up to N outside the Input section', () => {
251 const card = `# Gemma
252
253Gemma models support a context length of up to 8K while using RoPE.
254`
255 expect(parseNvidiaCard(card).contextWindow).toBe(8000)
256 })
257
258 it('classifies a completions route and a VLM messages route as chat', () => {
259 expect(
260 parseNvidiaCard(`## Prototype
261
262invoke_url='https://integrate.api.nvidia.com/v1/completions'
263`).activity,
264 ).toBe('chat')
265 expect(
266 parseNvidiaCard(`## Prototype
267
268invoke_url = "https://ai.api.nvidia.com/v1/vlm/adept/fuyu-8b"
269payload = {"messages": [{"role": "user", "content": ""}]}
270`).activity,
271 ).toBe('chat')
272 })
273
274 it('classifies an embedding card that names floats and no prototype URL', () => {
275 const card = `---
276description: "1B embedding model for semantic search."
277---
278
279## Output(s):
280
281**Output Type(s):** Floats <br>
282
283## Specifications
284
285- **Context Length:** 32,768 tokens
286`
287 expect(parseNvidiaCard(card)).toMatchObject({
288 activity: 'embeddings',
289 contextWindow: 32768,
290 })
291 expect(parseNvidiaCard(card).modalities).toBeUndefined()
292 })
293
294 it('reads an enable_thinking table as a toggle that can be off', () => {
295 const card = `# Nemotron
296
297| **Reasoning Mode** | Configurable on/off via chat template (\`enable_thinking=True/False\`) |
298`
299 expect(parseNvidiaCard(card).reasoning).toEqual({
300 mode: 'toggle',
301 mandatory: false,
302 })
303 })
304
305 it('reads a reasoning_effort list and an always-on sentence', () => {
306 expect(
307 parseNvidiaCard(
308 'Thinking budget is controlled by `reasoning_effort`, which accepts `low`,\n`high`, or `max` and defaults to `max`.',
309 ).reasoning,
310 ).toEqual({
311 mode: 'effort',
312 mandatory: null,
313 efforts: ['low', 'high', 'max'],
314 })
315 expect(
316 parseNvidiaCard(
317 '**Other Output Properties:** configurable low, high, or max reasoning effort. Thinking is always enabled.',
318 ).reasoning,
319 ).toEqual({
320 mode: 'effort',
321 mandatory: true,
322 efforts: ['low', 'high', 'max'],
323 })
324 expect(
325 parseNvidiaCard(
326 '- **Configurable reasoning effort:** Easily adjust the reasoning effort (low, medium, high) based on latency.',
327 ).reasoning,
328 ).toEqual({
329 mode: 'effort',
330 mandatory: null,
331 efforts: ['low', 'medium', 'high'],
332 })
333 })
334
335 it('does not invent a reasoning object from prose that names no request field', () => {
336 const card = `supported reasoning-strength settings are low, medium, high, and xhigh.
337Use the prompt token <|think|>.
338numeric reasoning effort from 1 to 100.
339
340## Capabilities
341
342- **Reasoning:** Supported
343`
344 const facts = parseNvidiaCard(card)
345 expect(facts.reasoning).toBeUndefined()
346 expect(facts.capabilities).toEqual(['reasoning'])
347 expect(facts.exactCapabilities).toBe(true)
348 })
349})
350
351describe('nvidia', () => {
352 it('joins listed ids to their cards and leaves prices null', async () => {
353 const urls = stubFetch({
354 [NVIDIA_MODELS_URL]: JSON.stringify(LISTING),
355 'https://build.nvidia.com/01-ai/yi-large.md': YI_CARD,
356 'https://build.nvidia.com/z-ai/glm-5-3-flash.md': GLM_CARD,
357 })
358
359 const listed = await provider.listModels({})
360 await expect(provider.fetchSpec({})).rejects.toThrow(
361 'parsed 0 generation specs',
362 )
363
364 const source = {
365 derivation: 'docs-derived',
366 sourceUrl: 'https://build.nvidia.com/z-ai/glm-5-3-flash',
367 sourceHash: await sha256Text(GLM_CARD),
368 }
369 expect(listed.models).toEqual([
370 {
371 rawId: '01-ai/yi-large',
372 releasedAt: 735790403,
373 pricing: null,
374 activity: 'chat',
375 factSources: {},
376 },
377 {
378 rawId: 'z-ai/glm-5.3-flash',
379 releasedAt: 735790403,
380 pricing: null,
381 activity: 'chat',
382 contextWindow: 1048576,
383 modalities: { input: ['text', 'image'], output: ['text'] },
384 exactCapabilities: true,
385 capabilities: ['tools', 'structured_outputs', 'reasoning'],
386 factSources: {
387 contextWindow: { ...source, path: 'contextWindow' },
388 modalities: { ...source, path: 'modalities' },
389 capabilities: {
390 tools: { ...source, path: 'capabilities.tools' },
391 structured_outputs: {
392 ...source,
393 path: 'capabilities.structured_outputs',
394 },
395 reasoning: { ...source, path: 'capabilities.reasoning' },
396 },
397 },
398 },
399 // No card under any slug: listed, no facts.
400 { rawId: 'google/deplot', releasedAt: 735790403, pricing: null },
401 ])
402 expect(urls).toContain('https://build.nvidia.com/z-ai/glm-5_3-flash.md')
403 })
404
405 it('throws when no card names a route', async () => {
406 stubFetch({ [NVIDIA_MODELS_URL]: JSON.stringify(LISTING) })
407 await expect(provider.listModels({})).rejects.toThrow(
408 'nvidia model cards: parsed 0 model rows',
409 )
410 })
411
412 it('lists the ids and reports the cards when every card fails to load', async () => {
413 globalThis.fetch = ((input: string) =>
414 Promise.resolve(
415 String(input) === NVIDIA_MODELS_URL
416 ? new Response(JSON.stringify(LISTING))
417 : new Response('busy', { status: 503 }),
418 )) as typeof fetch
419 const listed = await provider.listModels({})
420 expect(listed.models).toHaveLength(LISTING.data.length)
421 expect(listed.docsFailures).toMatchObject({
422 failed: LISTING.data.length + NVIDIA_REFERENCE_INDEXES.length + 1,
423 skipped: 0,
424 })
425 expect(listed.docsFailures?.first[0]?.error).toContain('503')
426 for (const model of listed.models) {
427 expect(model.absent).toEqual({
428 activity: 'unavailable',
429 contextWindow: 'unavailable',
430 maxOutput: 'unavailable',
431 modalities: 'unavailable',
432 capabilities: 'unavailable',
433 reasoning: 'unavailable',
434 requestMap: 'unavailable',
435 schemaEndpointId: 'unavailable',
436 })
437 }
438 })
439
440 const cards = (deplot: string) => ({
441 [NVIDIA_MODELS_URL]: JSON.stringify(LISTING),
442 'https://build.nvidia.com/01-ai/yi-large.md': YI_CARD,
443 'https://build.nvidia.com/google/deplot.md': deplot,
444 })
445
446 it('reads the HTML not-found page served with 200 as no card', async () => {
447 stubFetch(cards(NOT_FOUND_HTML))
448 const listed = await provider.listModels({})
449 expect(listed.models.find((m) => m.rawId === 'google/deplot')).toEqual({
450 rawId: 'google/deplot',
451 releasedAt: 735790403,
452 pricing: null,
453 })
454 })
455
456 it('keeps the other cards when one body is not a markdown card', async () => {
457 stubFetch(cards('<!DOCTYPE html><html><body>Just a moment</body></html>'))
458 const listed = await provider.listModels({})
459 expect(listed.docsFailures?.first).toMatchObject([
460 {
461 source: 'https://build.nvidia.com/google/deplot.md',
462 error:
463 'nvidia: https://build.nvidia.com/google/deplot.md is not a markdown card',
464 },
465 ])
466 const byId = new Map(listed.models.map((m) => [m.rawId, m]))
467 expect(byId.get('01-ai/yi-large')).toMatchObject({ activity: 'chat' })
468 expect(byId.get('01-ai/yi-large')?.absent).toBeUndefined()
469 expect(byId.get('google/deplot')?.absent).toMatchObject({
470 activity: 'unavailable',
471 })
472 })
473
474 it('ignores a card whose canonical URL is another page', async () => {
475 stubFetch(cards(YI_CARD))
476 const listed = await provider.listModels({})
477 expect(
478 listed.models.find((m) => m.rawId === 'google/deplot')?.activity,
479 ).toBeUndefined()
480 })
481
482 it('fills max output, reasoning, and the endpoint from that model OpenAPI', async () => {
483 const infer =
484 'https://docs.api.nvidia.com/nim/reference/z-ai-glm-5-3-flash-infer'
485 const openapi = `# OpenAPI definition
486
487\`\`\`json
488{
489 "openapi": "3.1.0",
490 "paths": {
491 "/chat/completions": {
492 "post": {
493 "requestBody": {
494 "content": {
495 "application/json": {
496 "schema": {
497 "type": "object",
498 "properties": {
499 "max_tokens": {
500 "type": "integer",
501 "maximum": 8192,
502 "minimum": 1,
503 "description": "The maximum number of tokens to generate."
504 },
505 "model": { "type": "string", "default": "z-ai/glm-5.3-flash" },
506 "reasoning_effort": { "type": "string", "enum": ["none", "high"] }
507 }
508 }
509 }
510 }
511 }
512 }
513 }
514 }
515}
516\`\`\`
517`
518 stubFetch({
519 [NVIDIA_MODELS_URL]: JSON.stringify(LISTING),
520 'https://build.nvidia.com/z-ai/glm-5-3-flash.md': GLM_CARD,
521 'https://build.nvidia.com/01-ai/yi-large.md': YI_CARD,
522 [NVIDIA_REFERENCE_INDEXES[0]!]: `---
523updatedAt: test
524---
525
526| Model | Endpoint |
527| --- | --- |
528| [z-ai / glm-5.3-flash](https://docs.api.nvidia.com/nim/reference/z-ai-glm-5-3-flash) | [chat](${infer}) |
529`,
530 [`${infer}.md`]: openapi,
531 })
532 const listed = await provider.listModels({})
533 const glm = listed.models.find(
534 (model) => model.rawId === 'z-ai/glm-5.3-flash',
535 )
536 expect(glm).toMatchObject({
537 maxOutput: 8192,
538 reasoning: {
539 mode: 'effort',
540 mandatory: null,
541 efforts: ['none', 'high'],
542 },
543 schemaEndpointId: 'z-ai/glm-5.3-flash',
544 })
545 expect(glm?.factSources?.maxOutput).toMatchObject({
546 sourceUrl: infer,
547 path: 'max_tokens',
548 })
549 expect(glm?.factSources?.contextWindow?.sourceUrl).toBe(
550 'https://build.nvidia.com/z-ai/glm-5-3-flash',
551 )
552 const spec = await provider.fetchSpec({})
553 expect(spec.skipped).toBeUndefined()
554 expect(spec.specs).toHaveLength(1)
555 expect(spec.specs[0]?.paths).toHaveProperty('/z-ai/glm-5.3-flash')
556 expect(
557 provider.classify('/z-ai/glm-5.3-flash', {
558 'x-modelschemas-activity': 'chat',
559 }),
560 ).toBe('chat')
561 })
562
563 it('does not copy an infer document that names a different model', async () => {
564 const infer =
565 'https://docs.api.nvidia.com/nim/reference/nvidia-nemotron-3-5-content-safety-infer'
566 const openapi = `# OpenAPI definition
567
568\`\`\`json
569{
570 "openapi": "3.1.0",
571 "info": { "title": "nvidia/nemotron-3-nano-omni-30b-a3b-reasoning" },
572 "paths": {
573 "/chat/completions": {
574 "post": {
575 "requestBody": {
576 "content": {
577 "application/json": {
578 "schema": {
579 "type": "object",
580 "properties": {
581 "model": {
582 "type": "string",
583 "default": "nvidia/nemotron-3-nano-omni-30b-a3b-reasoning"
584 },
585 "max_tokens": {
586 "type": "integer",
587 "maximum": 65536,
588 "description": "The maximum number of tokens to generate."
589 },
590 "reasoning_budget": { "type": "integer", "maximum": 32768 }
591 }
592 }
593 }
594 }
595 }
596 }
597 }
598 }
599}
600\`\`\`
601`
602 stubFetch({
603 [NVIDIA_MODELS_URL]: JSON.stringify({
604 object: 'list',
605 data: [
606 {
607 id: 'nvidia/nemotron-3.5-content-safety',
608 object: 'model',
609 created: 735790403,
610 owned_by: 'nvidia',
611 },
612 ],
613 }),
614 'https://build.nvidia.com/nvidia/nemotron-3.5-content-safety.md': `---
615title: "nemotron-3.5-content-safety"
616canonical: "https://build.nvidia.com/nvidia/nemotron-3.5-content-safety"
617---
618
619## Specifications
620
621- **Context Length:** 131,072 tokens
622- **Input:** Text
623- **Output:** Text
624
625## Capabilities
626
627- **Reasoning:** Supported
628
629${CHAT_PROTOTYPE('nvidia/nemotron-3.5-content-safety')}`,
630 [NVIDIA_REFERENCE_INDEXES[0]!]: `---
631updatedAt: test
632---
633
634| Model | Endpoint |
635| --- | --- |
636| [nvidia / nemotron-3.5-content-safety](https://docs.api.nvidia.com/nim/reference/nvidia-nemotron-3-5-content-safety) | [chat](${infer}) |
637`,
638 [`${infer}.md`]: openapi,
639 })
640 const listed = await provider.listModels({})
641 const safety = listed.models.find(
642 (model) => model.rawId === 'nvidia/nemotron-3.5-content-safety',
643 )
644 expect(safety?.maxOutput).toBeUndefined()
645 expect(safety?.reasoning).toBeUndefined()
646 expect(safety?.schemaEndpointId).toBeUndefined()
647 expect(safety?.contextWindow).toBe(131072)
648 await expect(provider.fetchSpec({})).rejects.toThrow(
649 'parsed 0 generation specs',
650 )
651 })
652})
653
654it('reads hosted replay instructions rather than copying maker behavior', () => {
655 const card =
656 '# Native card\n\n## Prototype\nPOST /v1/chat/completions\n\nClients must pass back the complete assistant message, including reasoning_content and tool_calls.'
657 expect(parseNvidiaCard(card).requestMap?.replayReasoningContent).toBe(true)
658 expect(
659 parseNvidiaCard(
660 card.replace(
661 'must pass back the complete assistant message, including',
662 'returns',
663 ),
664 ).requestMap,
665 ).toBeUndefined()
666})