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

dashscope-compat.test.ts

96 lines4.0 KB

1import { describe, expect, it } from 'vitest'
2​
3import {
4 dashscopeCompatCovers,
5 parseDashscopeCompat,
6 parseDashscopeCompatScope,
7} from './dashscope-compat.ts'
8​
9/**
10 * Request-parameter rows from
11 * compatibility-of-openai-with-dashscope.md, checked 2026-10-08.
12 * top_p says "keeps only the smallest set" and is not model-restricted.
13 * The Supported models line is the page's own compat scope.
14 */
15const COMPAT_FIXTURE = `
16Supported models: Qwen large language models (commercial and open-source editions), Qwen-VL, Qwen-Coder, Qwen-Omni, Qwen-Math, DeepSeek, Kimi, GLM, MiniMax.
17Qwen-Audio does not support the OpenAI compatible protocol.
18​
19## Request parameters
20​
21The request parameters are aligned with the OpenAI interface.
22​
23<table><tbody>
24<tr><td><p>model</p></td><td><p>string</p></td><td><p>-</p></td><td><p>The model to use.</p></td></tr>
25<tr><td><p>messages</p></td><td><p>array</p></td><td><p>-</p></td><td><p>Valid roles: system, user, assistant. Only messages[0] supports the system role.</p></td></tr>
26<tr><td><p>top_p</p></td><td><p>float</p></td><td><p>-</p></td><td><p>For example, a value of 0.8 keeps only the smallest set of tokens whose cumulative probability is at least 0.8.</p></td></tr>
27<tr><td><p>temperature</p></td><td><p>float</p></td><td><p>-</p></td><td><p>Controls the randomness and diversity of model responses.</p></td></tr>
28<tr><td><p>presence_penalty</p></td><td><p>float</p></td><td><p>-</p></td><td><p>Supported only on Qwen commercial models and open-source models qwen1.5 and later.</p></td></tr>
29<tr><td><p>n</p></td><td><p>integer</p></td><td><p>-</p></td><td><p>Currently supported only on qwen-plus.</p></td></tr>
30<tr><td><p>max_tokens</p></td><td><p>integer</p></td><td><p>-</p></td><td><p>The maximum number of tokens the model can generate.</p></td></tr>
31<tr><td><p>seed</p></td><td><p>integer</p></td><td><p>-</p></td><td><p>The random seed for generation.</p></td></tr>
32<tr><td><p>stop</p></td><td><p>string or array</p></td><td><p>-</p></td><td><p>Controls precise stopping of content generation.</p></td></tr>
33<tr><td><p>tools</p></td><td><p>array</p></td><td><p>-</p></td><td><p>Currently supported models: qwen-turbo, qwen-plus, and qwen-max.</p></td></tr>
34</tbody></table>
35​
36## Response parameters
38​
39describe('parseDashscopeCompat', () => {
40 it('maps unrestricted request parameters and leaves developer off', async () => {
41 const facts = await parseDashscopeCompat(COMPAT_FIXTURE)
42 expect(facts.flags).toEqual([
43 'top_p',
44 'temperature',
45 'max_tokens',
46 'seed',
47 'stop',
48 ])
49 expect(facts.requestMap).toEqual({
50 thinking: null,
51 maxTokensField: 'max_tokens',
52 developerRole: false,
53 replayReasoningContent: null,
54 store: null,
55 strictTools: null,
56 sessionAffinity: null,
57 cacheControl: null,
58 toolStream: null,
59 reasoningEffort: null,
60 })
61 expect(facts.sourceHash).toMatch(/^[0-9a-f]{64}$/)
62 expect(facts.scope).toEqual({
63 qwenLlm: true,
64 qwenKinds: ['vl', 'coder', 'omni', 'math'],
65 families: ['deepseek', 'kimi', 'glm', 'minimax'],
66 deny: ['audio'],
67 })
68 const scope = parseDashscopeCompatScope(COMPAT_FIXTURE)
69 for (const id of [
70 'qwen-plus',
71 'qwen3-omni-flash',
72 'deepseek-v4.1-flash',
73 'glm-5',
74 'kimi-k2',
75 'minimax-m2',
76 ]) {
77 expect(dashscopeCompatCovers(id, scope)).toBe(true)
78 }
79 expect(dashscopeCompatCovers('decision-model-preview', scope)).toBe(false)
80 expect(dashscopeCompatCovers('qwen-audio-turbo', scope)).toBe(false)
81 })
82​
83 it('throws when the request table is missing', async () => {
84 await expect(parseDashscopeCompat('# no table')).rejects.toThrow(
85 /parsed 0 request parameters|no request-parameter section/,
86 )
87 })
88​
89 it('names an HTML page as HTML, with its title', async () => {
90 await expect(
91 parseDashscopeCompat(
92 '<!DOCTYPE html><html><head><title>Just a moment</title></head></html>',
93 ),
94 ).rejects.toThrow(/response is HTML, not markdown \(title: Just a moment\)/)
95 })
96})