


























@@ -5,6 +5,7 @@ import { createQwenThinkingWrapper, wrapQwenProviderStream } from "./stream.js";
5566function capturePayload(params: {
77thinkingLevel?: "off" | "low" | "medium" | "high" | "xhigh" | "max";
8+thinkingFormat?: string;
89reasoning?: unknown;
910initialPayload?: Record<string, unknown>;
1011model?: Partial<Model<"openai-completions">>;
@@ -17,7 +18,11 @@ function capturePayload(params: {
1718return {} as ReturnType<StreamFn>;
1819};
192020-const wrapped = createQwenThinkingWrapper(baseStreamFn, params.thinkingLevel ?? "high");
21+const wrapped = createQwenThinkingWrapper(
22+baseStreamFn,
23+params.thinkingLevel ?? "high",
24+params.thinkingFormat,
25+);
2126void wrapped(
2227{
2328api: "openai-completions",
@@ -56,6 +61,37 @@ describe("createQwenThinkingWrapper", () => {
5661expect(capturePayload({ thinkingLevel: "high" })).toEqual({ enable_thinking: true });
5762});
586364+it("overrides qwen-chat-template thinking with the session level", () => {
65+expect(
66+capturePayload({
67+thinkingFormat: "qwen-chat-template",
68+thinkingLevel: "off",
69+initialPayload: {
70+chat_template_kwargs: { enable_thinking: true, preserve_thinking: true },
71+enable_thinking: true,
72+reasoning_effort: "high",
73+},
74+}),
75+).toEqual({
76+chat_template_kwargs: { enable_thinking: false, preserve_thinking: true },
77+});
78+});
79+80+it("uses the runtime model qwen-chat-template format when the wrapper context omits it", () => {
81+expect(
82+capturePayload({
83+thinkingLevel: "off",
84+model: { compat: { thinkingFormat: "qwen-chat-template" } },
85+initialPayload: {
86+chat_template_kwargs: { enable_thinking: true },
87+enable_thinking: true,
88+},
89+}),
90+).toEqual({
91+chat_template_kwargs: { enable_thinking: false, preserve_thinking: true },
92+});
93+});
94+5995it("skips non-reasoning and non-completions models", () => {
6096expect(capturePayload({ model: { reasoning: false } })).toStrictEqual({});
6197expect(capturePayload({ model: { api: "openai-responses" as never } })).toStrictEqual({});
@@ -64,19 +100,18 @@ describe("createQwenThinkingWrapper", () => {
6410065101describe("wrapQwenProviderStream", () => {
66102it("only registers for Qwen-family OpenAI-compatible providers", () => {
67-expect(
68-wrapQwenProviderStream({
69-provider: "qwencloud",
70-modelId: "qwen3.6-plus",
71-model: {
72-api: "openai-completions",
73-provider: "qwen",
74-id: "qwen3.6-plus",
75-reasoning: true,
76-} as Model<"openai-completions">,
77-streamFn: undefined,
78-} as never),
79-).toBeTypeOf("function");
103+const streamFn = wrapQwenProviderStream({
104+provider: "qwencloud",
105+modelId: "qwen3.6-plus",
106+model: {
107+api: "openai-completions",
108+provider: "qwen",
109+id: "qwen3.6-plus",
110+reasoning: true,
111+} as Model<"openai-completions">,
112+streamFn: undefined,
113+} as never);
114+expect(streamFn).toBeTypeOf("function");
8011581116expect(
82117wrapQwenProviderStream({
@@ -91,4 +126,46 @@ describe("wrapQwenProviderStream", () => {
91126} as never),
92127).toBeUndefined();
93128});
129+130+it("passes qwen-chat-template format to the Qwen wrapper", () => {
131+let captured: Record<string, unknown> = {};
132+const baseStreamFn: StreamFn = (_model, _context, options) => {
133+const payload = {
134+chat_template_kwargs: { enable_thinking: true },
135+enable_thinking: true,
136+};
137+options?.onPayload?.(payload, _model);
138+captured = payload;
139+return {} as ReturnType<StreamFn>;
140+};
141+142+const wrapped = wrapQwenProviderStream({
143+provider: "qwen",
144+modelId: "qwen3.6-plus",
145+model: {
146+api: "openai-completions",
147+provider: "qwen",
148+id: "qwen3.6-plus",
149+reasoning: true,
150+compat: { thinkingFormat: "qwen-chat-template" },
151+} as Model<"openai-completions">,
152+streamFn: baseStreamFn,
153+thinkingLevel: "off",
154+} as never);
155+156+void wrapped?.(
157+{
158+api: "openai-completions",
159+provider: "qwen",
160+id: "qwen3.6-plus",
161+reasoning: true,
162+} as Model<"openai-completions">,
163+{ messages: [] } as Context,
164+{},
165+);
166+167+expect(captured).toStrictEqual({
168+chat_template_kwargs: { enable_thinking: false, preserve_thinking: true },
169+});
170+});
94171});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。