Skip to content

Commit 677a55a

Browse files
committed
fix(provider): map reasoning_content to <thinking> tags for preserve_thinking compatibility
1 parent 2115df5 commit 677a55a

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

packages/opencode/src/provider/transform.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,39 @@ function normalizeMessages(
214214
})
215215
}
216216

217+
const isQwen = model.id.toLowerCase().includes("qwen") || model.api.id.toLowerCase().includes("qwen")
218+
const preserveReasoningInContent =
219+
_options?.preserveReasoningInContent === true ||
220+
(model.options as any)?.preserveReasoningInContent === true
221+
222+
if (isQwen || preserveReasoningInContent) {
223+
msgs = msgs.map((msg) => {
224+
if (msg.role === "assistant" && Array.isArray(msg.content)) {
225+
const reasoningParts = msg.content.filter((part: any) => part.type === "reasoning")
226+
const reasoningText = reasoningParts.map((part: any) => part.text).join("")
227+
228+
if (reasoningText) {
229+
const filteredContent = msg.content.filter((part: any) => part.type !== "reasoning")
230+
return {
231+
...msg,
232+
content: [
233+
{ type: "text", text: `<thinking>${reasoningText}</thinking>\n\n` },
234+
...filteredContent,
235+
],
236+
providerOptions: {
237+
...msg.providerOptions,
238+
openaiCompatible: {
239+
...msg.providerOptions?.openaiCompatible,
240+
reasoning_content: undefined,
241+
},
242+
},
243+
}
244+
}
245+
}
246+
return msg
247+
})
248+
}
249+
217250
if (
218251
typeof model.capabilities.interleaved === "object" &&
219252
model.capabilities.interleaved.field &&

0 commit comments

Comments
 (0)