File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import OpenAI from "openai"
44import type { ModelInfo } from "@roo-code/types"
55
66import { type ApiHandlerOptions , getModelMaxOutputTokens } from "../../shared/api"
7+ import { XmlMatcher } from "../../utils/xml-matcher"
78import { ApiStream } from "../transform/stream"
89import { convertToOpenAiMessages } from "../transform/openai-format"
910
@@ -105,13 +106,21 @@ export abstract class BaseOpenAiCompatibleProvider<ModelName extends string>
105106 ) : ApiStream {
106107 const stream = await this . createStream ( systemPrompt , messages , metadata )
107108
109+ const matcher = new XmlMatcher (
110+ "think" ,
111+ ( chunk ) =>
112+ ( {
113+ type : chunk . matched ? "reasoning" : "text" ,
114+ text : chunk . data ,
115+ } ) as const ,
116+ )
117+
108118 for await ( const chunk of stream ) {
109119 const delta = chunk . choices [ 0 ] ?. delta
110120
111121 if ( delta ?. content ) {
112- yield {
113- type : "text" ,
114- text : delta . content ,
122+ for ( const processedChunk of matcher . update ( delta . content ) ) {
123+ yield processedChunk
115124 }
116125 }
117126
@@ -127,6 +136,11 @@ export abstract class BaseOpenAiCompatibleProvider<ModelName extends string>
127136 }
128137 }
129138 }
139+
140+ // Process any remaining content
141+ for ( const processedChunk of matcher . final ( ) ) {
142+ yield processedChunk
143+ }
130144 }
131145
132146 async completePrompt ( prompt : string ) : Promise < string > {
You can’t perform that action at this time.
0 commit comments