File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed
Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import { convertToR1Format } from "../transform/r1-format"
1414import { convertToSimpleMessages } from "../transform/simple-format"
1515import { ApiStream , ApiStreamUsageChunk } from "../transform/stream"
1616import { BaseProvider } from "./base-provider"
17+ import { XmlMatcher } from "../../utils/xml-matcher"
1718
1819const DEEP_SEEK_DEFAULT_TEMPERATURE = 0.6
1920
@@ -134,15 +135,23 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
134135
135136 const stream = await this . client . chat . completions . create ( requestOptions )
136137
138+ const matcher = new XmlMatcher (
139+ "think" ,
140+ ( chunk ) =>
141+ ( {
142+ type : chunk . matched ? "reasoning" : "text" ,
143+ text : chunk . data ,
144+ } ) as const ,
145+ )
146+
137147 let lastUsage
138148
139149 for await ( const chunk of stream ) {
140150 const delta = chunk . choices [ 0 ] ?. delta ?? { }
141151
142152 if ( delta . content ) {
143- yield {
144- type : "text" ,
145- text : delta . content ,
153+ for ( const chunk of matcher . update ( delta . content ) ) {
154+ yield chunk
146155 }
147156 }
148157
@@ -156,6 +165,9 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
156165 lastUsage = chunk . usage
157166 }
158167 }
168+ for ( const chunk of matcher . final ( ) ) {
169+ yield chunk
170+ }
159171
160172 if ( lastUsage ) {
161173 yield this . processUsageMetrics ( lastUsage , modelInfo )
You can’t perform that action at this time.
0 commit comments