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
@@ -99,15 +100,23 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
99100
100101 const stream = await this . client . chat . completions . create ( requestOptions )
101102
103+ const matcher = new XmlMatcher (
104+ "think" ,
105+ ( chunk ) =>
106+ ( {
107+ type : chunk . matched ? "reasoning" : "text" ,
108+ text : chunk . data ,
109+ } ) as const ,
110+ )
111+
102112 let lastUsage
103113
104114 for await ( const chunk of stream ) {
105115 const delta = chunk . choices [ 0 ] ?. delta ?? { }
106116
107117 if ( delta . content ) {
108- yield {
109- type : "text" ,
110- text : delta . content ,
118+ for ( const chunk of matcher . update ( delta . content ) ) {
119+ yield chunk
111120 }
112121 }
113122
@@ -121,6 +130,9 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
121130 lastUsage = chunk . usage
122131 }
123132 }
133+ for ( const chunk of matcher . final ( ) ) {
134+ yield chunk
135+ }
124136
125137 if ( lastUsage ) {
126138 yield this . processUsageMetrics ( lastUsage , modelInfo )
You can’t perform that action at this time.
0 commit comments