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

cerebras-reasoning.test.ts

123 lines4.3 KB

1import { describe, expect, it } from 'vitest'
2​
3import {
4 cerebrasRequestMap,
5 cerebrasThinking,
6 parseCerebrasChatSpec,
7 parseCerebrasReasoning,
8} from './cerebras-reasoning.ts'
9​
10/** Rows from https://inference-docs.cerebras.ai/capabilities/reasoning.md */
11const REASONING = `
12| Model | Default | \`reasoning_effort\` | Disable reasoning | Availability |
13| - | - | - | - | - |
14| [\`qwen-3.8-27b\`](/models/qwen-3.8-27b) | \`high\` | \`none\`, \`low\`, \`medium\`, \`high\` | Set \`reasoning_effort\` to \`none\` | Shared Inference |
15| \`kimi-k2.7-code\` | Always enabled | Accepted but ignored | Not supported | Customer trials only |
16| [\`gpt-oss-120b\`](/models/openai-oss) | \`medium\` | \`low\`, \`medium\`, \`high\` | Not supported | Shared Inference |
17| [\`gemma-4-31b\`](/dedicated/overview#supported-models) | Disabled | \`none\`, \`low\`, \`medium\`, \`high\` | Set \`reasoning_effort\` to \`none\` | Dedicated Inference |
18​
19| Model | Default response behavior | \`raw\` | \`hidden\` |
20| - | - | - | - |
21| \`qwen-3.8-27b\` | Reasoning returned separately | Does not change the separated response format | Not supported |
23​
24/** The chat-spec sentences the request map is allowed to trust. */
25const SPEC = `
26 max_completion_tokens:
27 type: integer
28 nullable: true
29 description: >
30 The maximum number of tokens that can be generated in the
31 completion, including reasoning tokens.
32 max_tokens:
33 type: integer
34 nullable: true
35 description: >
36 An alias for \`max_completion_tokens\`. Do not send both parameters
37 in the same request.
38 description: >
39 A message in the conversation. Developer messages are supported only by \`gpt-oss-120b\`.
41​
42describe('cerebras reasoning table', () => {
43 const parsed = parseCerebrasReasoning(REASONING)
44​
45 it('reads effort lists and whether reasoning can be disabled', () => {
46 expect(parsed.configured.get('qwen-3.8-27b')).toEqual({
47 mode: 'effort',
48 mandatory: false,
49 efforts: ['none', 'low', 'medium', 'high'],
50 })
51 expect(parsed.configured.get('gpt-oss-120b')).toEqual({
52 mode: 'effort',
53 mandatory: true,
54 efforts: ['low', 'medium', 'high'],
55 })
56 expect(parsed.configured.get('gemma-4-31b')?.mandatory).toBe(false)
57 expect(parsed.ignored).toEqual(['kimi-k2.7-code'])
58 })
59​
60 it('throws when a disable cell is neither none nor not supported', () => {
61 expect(() =>
62 parseCerebrasReasoning(`
63| Model | Default | \`reasoning_effort\` | Disable reasoning | Availability |
64| - | - | - | - | - |
65| \`gpt-oss-120b\` | \`medium\` | \`low\`, \`high\` | Sometimes | Shared Inference |
66`),
67 ).toThrow(/unread disable cell/)
68 })
69})
70​
71describe('cerebras chat spec', () => {
72 const spec = parseCerebrasChatSpec(SPEC)
73​
74 it('keeps max_completion_tokens and the developer-role ids', () => {
75 expect(spec).toEqual({
76 maxTokensField: 'max_completion_tokens',
77 developerIds: ['gpt-oss-120b'],
78 })
79 })
80​
81 it('throws when max_tokens stops being the alias', () => {
82 expect(() =>
83 parseCerebrasChatSpec(SPEC.replace('An alias for', 'Previously')),
84 ).toThrow(/not an alias/)
85 })
86​
87 it('maps qwen off to none and leaves gpt-oss with no off body', () => {
88 const reasoning = parseCerebrasReasoning(REASONING)
89 expect(cerebrasThinking(['none', 'low', 'medium', 'high'])).toEqual({
90 on: { reasoning_effort: 'high' },
91 off: { reasoning_effort: 'none' },
92 levels: {
93 off: 'none',
94 minimal: null,
95 low: 'low',
96 medium: 'medium',
97 high: 'high',
98 xhigh: null,
99 max: null,
100 },
101 })
102 const qwen = cerebrasRequestMap(
103 'qwen-3.8-27b',
104 spec,
105 reasoning.configured.get('qwen-3.8-27b'),
106 false,
107 )
108 const oss = cerebrasRequestMap(
109 'gpt-oss-120b',
110 spec,
111 reasoning.configured.get('gpt-oss-120b'),
112 false,
113 )
114 expect(qwen.developerRole).toBe(false)
115 expect(qwen.thinking?.off).toEqual({ reasoning_effort: 'none' })
116 expect(qwen.reasoningEffort).toBe(true)
117 expect(oss.developerRole).toBe(true)
118 expect(oss.thinking?.off).toBeNull()
119 expect(oss.maxTokensField).toBe('max_completion_tokens')
120 expect(oss.replayReasoningContent).toBeNull()
121 expect(oss.toolStream).toBeNull()
122 })
123})