@@ -558,7 +558,7 @@ async function receiveStream(model: string, stream: any, refConvId?: string): Pr
558
558
choices : [
559
559
{
560
560
index : 0 ,
561
- message : { role : "assistant" , content : "" } ,
561
+ message : { role : "assistant" , content : "" , reasoning_content : "" } ,
562
562
finish_reason : "stop" ,
563
563
} ,
564
564
] ,
@@ -581,20 +581,25 @@ async function receiveStream(model: string, stream: any, refConvId?: string): Pr
581
581
refContent += searchResults . map ( item => `${ item . title } - ${ item . url } ` ) . join ( '\n' ) ;
582
582
return ;
583
583
}
584
- if ( result . choices [ 0 ] . delta . type === "thinking" ) {
584
+ if ( isFoldModel && result . choices [ 0 ] . delta . type === "thinking" ) {
585
585
if ( ! thinking && isThinkingModel && ! isSilentModel ) {
586
586
thinking = true ;
587
587
data . choices [ 0 ] . message . content += isFoldModel ? "<details><summary>思考过程</summary><pre>" : "[思考开始]\n" ;
588
588
}
589
589
if ( isSilentModel )
590
590
return ;
591
591
}
592
- else if ( thinking && isThinkingModel && ! isSilentModel ) {
592
+ else if ( isFoldModel && thinking && isThinkingModel && ! isSilentModel ) {
593
593
thinking = false ;
594
594
data . choices [ 0 ] . message . content += isFoldModel ? "</pre></details>" : "\n\n[思考结束]\n" ;
595
595
}
596
- if ( result . choices [ 0 ] . delta . content )
597
- data . choices [ 0 ] . message . content += result . choices [ 0 ] . delta . content ;
596
+ if ( result . choices [ 0 ] . delta . content ) {
597
+ if ( result . choices [ 0 ] . delta . type === "thinking" && ! isFoldModel ) {
598
+ data . choices [ 0 ] . message . reasoning_content += result . choices [ 0 ] . delta . content ;
599
+ } else {
600
+ data . choices [ 0 ] . message . content += result . choices [ 0 ] . delta . content ;
601
+ }
602
+ }
598
603
if ( result . choices && result . choices [ 0 ] && result . choices [ 0 ] . finish_reason === "stop" ) {
599
604
data . choices [ 0 ] . message . content = data . choices [ 0 ] . message . content . replace ( / ^ \n + / , '' ) . replace ( / \[ c i t a t i o n : \d + \] / g, '' ) + ( refContent ? `\n\n搜索结果来自:\n${ refContent } ` : '' ) ;
600
605
resolve ( data ) ;
@@ -640,7 +645,7 @@ function createTransStream(model: string, stream: any, refConvId: string, endCal
640
645
choices : [
641
646
{
642
647
index : 0 ,
643
- delta : { role : "assistant" , content : "" } ,
648
+ delta : { role : "assistant" , content : "" , reasoning_content : "" } ,
644
649
finish_reason : null ,
645
650
} ,
646
651
] ,
@@ -676,7 +681,7 @@ function createTransStream(model: string, stream: any, refConvId: string, endCal
676
681
}
677
682
return ;
678
683
}
679
- if ( result . choices [ 0 ] . delta . type === "thinking" ) {
684
+ if ( isFoldModel && result . choices [ 0 ] . delta . type === "thinking" ) {
680
685
if ( ! thinking && isThinkingModel && ! isSilentModel ) {
681
686
thinking = true ;
682
687
transStream . write ( `data: ${ JSON . stringify ( {
@@ -696,7 +701,7 @@ function createTransStream(model: string, stream: any, refConvId: string, endCal
696
701
if ( isSilentModel )
697
702
return ;
698
703
}
699
- else if ( thinking && isThinkingModel && ! isSilentModel ) {
704
+ else if ( isFoldModel && thinking && isThinkingModel && ! isSilentModel ) {
700
705
thinking = false ;
701
706
transStream . write ( `data: ${ JSON . stringify ( {
702
707
id : `${ refConvId } @${ result . message_id } ` ,
@@ -716,19 +721,25 @@ function createTransStream(model: string, stream: any, refConvId: string, endCal
716
721
if ( ! result . choices [ 0 ] . delta . content )
717
722
return ;
718
723
724
+ const deltaContent = result . choices [ 0 ] . delta . content . replace ( / \[ c i t a t i o n : \d + \] / g, '' ) ;
725
+ const delta = result . choices [ 0 ] . delta . type === "thinking" && ! isFoldModel
726
+ ? { role : "assistant" , reasoning_content : deltaContent }
727
+ : { role : "assistant" , content : deltaContent } ;
728
+
719
729
transStream . write ( `data: ${ JSON . stringify ( {
720
730
id : `${ refConvId } @${ result . message_id } ` ,
721
731
model : result . model ,
722
732
object : "chat.completion.chunk" ,
723
733
choices : [
724
734
{
725
735
index : 0 ,
726
- delta : { role : "assistant" , content : result . choices [ 0 ] . delta . content . replace ( / \[ c i t a t i o n : \d + \] / g , '' ) } ,
736
+ delta,
727
737
finish_reason : null ,
728
738
} ,
729
739
] ,
730
740
created,
731
741
} ) } \n\n`) ;
742
+
732
743
if ( result . choices && result . choices [ 0 ] && result . choices [ 0 ] . finish_reason === "stop" ) {
733
744
transStream . write ( `data: ${ JSON . stringify ( {
734
745
id : `${ refConvId } @${ result . message_id } ` ,
0 commit comments