File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -81,7 +81,28 @@ export class GeminiHandler extends BaseProvider implements SingleCompletionHandl
8181 let lastUsageMetadata : GenerateContentResponseUsageMetadata | undefined
8282
8383 for await ( const chunk of result ) {
84- if ( chunk . text ) {
84+ // Process candidates and their parts to separate thoughts from content
85+ if ( chunk . candidates && chunk . candidates . length > 0 ) {
86+ const candidate = chunk . candidates [ 0 ]
87+ if ( candidate . content && candidate . content . parts ) {
88+ for ( const part of candidate . content . parts ) {
89+ if ( part . thought ) {
90+ // This is a thinking/reasoning part
91+ if ( part . text ) {
92+ yield { type : "reasoning" , text : part . text }
93+ }
94+ } else {
95+ // This is regular content
96+ if ( part . text ) {
97+ yield { type : "text" , text : part . text }
98+ }
99+ }
100+ }
101+ }
102+ }
103+
104+ // Fallback to the original text property if no candidates structure
105+ else if ( chunk . text ) {
85106 yield { type : "text" , text : chunk . text }
86107 }
87108
@@ -121,7 +142,7 @@ export class GeminiHandler extends BaseProvider implements SingleCompletionHandl
121142 id,
122143 info,
123144 thinkingConfig : this . options . modelMaxThinkingTokens
124- ? { thinkingBudget : this . options . modelMaxThinkingTokens }
145+ ? { thinkingBudget : this . options . modelMaxThinkingTokens , includeThoughts : true }
125146 : undefined ,
126147 maxOutputTokens : this . options . modelMaxTokens ?? info . maxTokens ?? undefined ,
127148 }
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ export class VertexHandler extends GeminiHandler implements SingleCompletionHand
2424 id,
2525 info,
2626 thinkingConfig : this . options . modelMaxThinkingTokens
27- ? { thinkingBudget : this . options . modelMaxThinkingTokens }
27+ ? { thinkingBudget : this . options . modelMaxThinkingTokens , includeThoughts : true }
2828 : undefined ,
2929 maxOutputTokens : this . options . modelMaxTokens ?? info . maxTokens ?? undefined ,
3030 }
You can’t perform that action at this time.
0 commit comments