Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2
3import { provider } from './adapters/sambanova.ts'
4import {
5 parseSambanovaChatFlags,
6 parseSambanovaModelModalities,
7 parseSambanovaToolModels,
8 sambanovaDocsPatch,
9 SAMBANOVA_MODELS_DOCS_URL,
10 SAMBANOVA_SPEC_URL,
11 SAMBANOVA_TOOLS_DOCS_URL,
12} from './sambanova-docs.ts'
13
14const MODELS_PAGE = `
15# SambaCloud models overview and specifications
16
17## Production models
18
19| **Developer** | **Model ID** | **Context length** | **Supported modalities** | **View on Hugging Face** |
20| :- | :- | :- | :- | :- |
21| **MiniMax** | \`MiniMax-M2.7\` | 192k tokens | Text | [Model card](https://huggingface.co/MiniMaxAI/MiniMax-M2.7) |
22| **DeepSeek** | \`DeepSeek-V3.1\` | 128k tokens | Text | [Model card](https://huggingface.co/deepseek-ai/DeepSeek-V3.1) |
23| **Meta** | \`Meta-Llama-3.3-70B-Instruct\` | 128k tokens | Text | [Model card](https://huggingface.co/meta-llama/Llama-3.3-70B-Instruct) |
24| **OpenAI** | \`gpt-oss-120b\` | 128k tokens | Text | [Model card](https://huggingface.co/openai/gpt-oss-120b) |
25
26## Preview models
27
28| **Developer** | **Model ID** | **Context length** | **Supported modalities** | **View on Hugging Face** |
29| :- | :- | :- | :- | :- |
30| **MiniMax** | \`MiniMax-M3\` | 1M tokens | Text | [Model card](https://huggingface.co/MiniMaxAI/MiniMax-M3) |
31| **DeepSeek** | \`DeepSeek-V3.2\` | 32k tokens | Text | [Model card](https://huggingface.co/deepseek-ai/DeepSeek-V3.2) |
32| **Google** | \`gemma-4-31B-it\` | 128k tokens | Text, Image, Video | [Model card](https://huggingface.co/google/gemma-4-31B-it) |
33`
34
35const TOOLS_PAGE = `
36## Supported models
37
38* \`Meta-Llama-3.3-70B-Instruct\`
39* \`gpt-oss-120b\`
40* \`DeepSeek-V3.1\`
41* \`DeepSeek-V3.2\`
42* \`MiniMax-M2.7\`
43* \`MiniMax-M3\`
44* \`gemma-4-31B-it\`
45
46<Note>
47 To get better quality in tool calling requests with \`gpt-oss-120b\`, set the \`reasoning_effort\` to \`high\`.
48</Note>
49
50## Example usage
51`
52
53const CHAT_SPEC = {
54 components: {
55 schemas: {
56 ChatCompletionRequest: {
57 properties: {
58 max_tokens: {
59 description: 'The maximum number of tokens that can be generated.',
60 },
61 max_completion_tokens: {
62 description: 'The maximum number of tokens that can be generated.',
63 },
64 temperature: { description: 'Sampling temperature.' },
65 top_p: { description: 'Nucleus sampling.' },
66 top_k: { description: 'Top-k sampling.' },
67 presence_penalty: {
68 description:
69 'Not currently implemented; accepted for API compatibility',
70 },
71 frequency_penalty: {
72 description:
73 'Not currently implemented; accepted for API compatibility',
74 },
75 repetition_penalty: {
76 description:
77 'Only supported for some models (currently MiniMax and gpt-oss models); silently ignored on models that do not support it.',
78 },
79 stop: { description: 'Stop sequences.' },
80 response_format: {
81 description:
82 'Setting to `{ "type": "json_schema", "json_schema": {<your_schema>}"}` enables JSON schema mode.',
83 },
84 reasoning_effort: {
85 description: "allowed values are 'low', 'medium', 'high'",
86 enum: ['low', 'medium', 'high'],
87 },
88 tool_choice: { description: 'Which tool is called.' },
89 tools: { description: 'Tools the model may call.' },
90 seed: { description: 'Best-effort deterministic sampling.' },
91 },
92 },
93 },
94 },
95}
96
97const TEXT = { input: ['text'], output: ['text'] }
98const GEMMA = { input: ['text', 'image', 'video'], output: ['text'] }
99
100describe('parseSambanovaModelModalities', () => {
101 it('reads both tables and treats image and video as inputs', () => {
102 const rows = parseSambanovaModelModalities(MODELS_PAGE)
103 expect(rows.get('DeepSeek-V3.1')).toEqual(TEXT)
104 expect(rows.get('MiniMax-M3')).toEqual(TEXT)
105 expect(rows.get('gemma-4-31B-it')).toEqual(GEMMA)
106 expect(rows.size).toBe(7)
107 })
108
109 it('throws when the table is missing or a modality is unknown', () => {
110 expect(() => parseSambanovaModelModalities('# no table')).toThrow(
111 /no modalities table/,
112 )
113 expect(() =>
114 parseSambanovaModelModalities(
115 MODELS_PAGE.replace('Text, Image, Video', 'Text, Hologram'),
116 ),
117 ).toThrow(/unknown modality/)
118 })
119})
120
121describe('parseSambanovaToolModels', () => {
122 it('reads the supported-models bullets and ignores the note', () => {
123 expect([...parseSambanovaToolModels(TOOLS_PAGE)].sort()).toEqual([
124 'DeepSeek-V3.1',
125 'DeepSeek-V3.2',
126 'Meta-Llama-3.3-70B-Instruct',
127 'MiniMax-M2.7',
128 'MiniMax-M3',
129 'gemma-4-31B-it',
130 'gpt-oss-120b',
131 ])
132 })
133
134 it('throws when the section names no ids', () => {
135 expect(() =>
136 parseSambanovaToolModels('## Supported models\n\n## Example usage\n'),
137 ).toThrow(/no model ids/)
138 })
139})
140
141describe('parseSambanovaChatFlags', () => {
142 it('keeps implemented fields and drops unimplemented ones', () => {
143 expect(parseSambanovaChatFlags(CHAT_SPEC)).toEqual([
144 'tools',
145 'tool_choice',
146 'max_tokens',
147 'temperature',
148 'top_p',
149 'top_k',
150 'stop',
151 'seed',
152 'response_format',
153 'structured_outputs',
154 'reasoning_effort',
155 ])
156 })
157
158 it('throws when the chat schema is missing', () => {
159 expect(() => parseSambanovaChatFlags({ components: {} })).toThrow(
160 /ChatCompletionRequest/,
161 )
162 })
163})
164
165describe('sambanovaDocsPatch', () => {
166 const loaded = {
167 modalities: {
168 byId: Object.fromEntries(parseSambanovaModelModalities(MODELS_PAGE)),
169 hash: 'models',
170 },
171 flags: { flags: parseSambanovaChatFlags(CHAT_SPEC), hash: 'spec' },
172 tools: { ids: [...parseSambanovaToolModels(TOOLS_PAGE)], hash: 'tools' },
173 }
174
175 it('attaches text modalities and drops seed on gemma', () => {
176 const llama = sambanovaDocsPatch('Meta-Llama-3.3-70B-Instruct', loaded)
177 expect(llama.modalities).toEqual(TEXT)
178 expect(llama.capabilities).toContain('seed')
179 expect(llama.capabilities).toContain('tools')
180 expect(llama.exactCapabilities).toBe(true)
181 expect(llama.factSources?.modalities).toMatchObject({
182 derivation: 'docs-derived',
183 sourceUrl: SAMBANOVA_MODELS_DOCS_URL,
184 })
185 expect(llama.factSources?.capabilities?.tools).toMatchObject({
186 derivation: 'docs-derived',
187 sourceUrl: SAMBANOVA_TOOLS_DOCS_URL,
188 })
189 expect(llama.factSources?.capabilities?.temperature).toMatchObject({
190 derivation: 'upstream-spec',
191 sourceUrl: SAMBANOVA_SPEC_URL,
192 })
193
194 const gemma = sambanovaDocsPatch('gemma-4-31B-it', loaded)
195 expect(gemma.modalities).toEqual(GEMMA)
196 expect(gemma.capabilities).not.toContain('seed')
197 expect(gemma.capabilities).toContain('tools')
198 })
199
200 it('omits tools for an id the function-calling page does not list', () => {
201 const patch = sambanovaDocsPatch('not-a-tool-model', {
202 ...loaded,
203 modalities: {
204 byId: { 'not-a-tool-model': TEXT },
205 hash: 'models',
206 },
207 })
208 expect(patch.capabilities).not.toContain('tools')
209 expect(patch.capabilities).not.toContain('tool_choice')
210 expect(patch.capabilities).toContain('temperature')
211 })
212
213 it('keeps stored facts when a source failed to load', () => {
214 expect(
215 sambanovaDocsPatch('gemma-4-31B-it', {
216 modalities: null,
217 flags: null,
218 tools: null,
219 }).absent,
220 ).toEqual({ modalities: 'unavailable', capabilities: 'unavailable' })
221 })
222})
223
224describe('sambanova listModels docs', () => {
225 it('joins the listing to the models page and the chat schema', async () => {
226 const original = globalThis.fetch
227 globalThis.fetch = ((url: string) => {
228 const href = String(url)
229 const body = href.includes('/v1/models')
230 ? JSON.stringify({
231 data: [
232 {
233 id: 'gemma-4-31B-it',
234 context_length: 262144,
235 max_completion_tokens: 262144,
236 pricing: {
237 prompt: '0.00000038',
238 completion: '0.00000115',
239 },
240 },
241 {
242 id: 'MiniMax-M3',
243 context_length: 1048576,
244 max_completion_tokens: 1048576,
245 pricing: {
246 prompt: '0.00000060',
247 completion: '0.00000240',
248 input_cache_read: '0.00000006',
249 input_cache_write: '0.00000000',
250 },
251 },
252 ],
253 })
254 : href.endsWith('/sambacloud-models.md')
255 ? MODELS_PAGE
256 : href.endsWith('/function-calling.md')
257 ? TOOLS_PAGE
258 : JSON.stringify(CHAT_SPEC)
259 return Promise.resolve(new Response(body, { status: 200 }))
260 }) as typeof fetch
261 try {
262 const { models } = await provider.listModels({
263 SAMBANOVA_API_KEY: 'test',
264 })
265 const gemma = models.find((model) => model.rawId === 'gemma-4-31B-it')
266 const minimax = models.find((model) => model.rawId === 'MiniMax-M3')
267 expect(gemma?.modalities).toEqual(GEMMA)
268 expect(gemma?.capabilities).not.toContain('seed')
269 expect(gemma?.capabilities).toContain('reasoning_effort')
270 expect(gemma?.contextWindow).toBe(262144)
271 expect(minimax?.modalities).toEqual(TEXT)
272 expect(minimax?.capabilities).toContain('seed')
273 const card = minimax?.pricing as {
274 tables?: { rate?: { base?: Record<string, number> } }
275 }
276 expect(card.tables?.rate?.base?.cache_read_tokens).toBeCloseTo(
277 0.00000006,
278 12,
279 )
280 expect(card.tables?.rate?.base?.cache_write_tokens).toBeUndefined()
281 } finally {
282 globalThis.fetch = original
283 }
284 })
285})