File tree Expand file tree Collapse file tree
packages/opencode/src/provider Expand file tree Collapse file tree Original file line number Diff line number Diff 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 &&
You can’t perform that action at this time.
0 commit comments