@@ -191,7 +191,7 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
191191 let lastUsage
192192
193193 for await ( const chunk of stream ) {
194- const delta = chunk . choices [ 0 ] ?. delta ?? { }
194+ const delta = chunk . choices ?. [ 0 ] ?. delta ?? { }
195195
196196 if ( delta . content ) {
197197 for ( const chunk of matcher . update ( delta . content ) ) {
@@ -242,7 +242,7 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
242242
243243 yield {
244244 type : "text" ,
245- text : response . choices [ 0 ] ?. message . content || "" ,
245+ text : response . choices ?. [ 0 ] ?. message . content || "" ,
246246 }
247247
248248 yield this . processUsageMetrics ( response . usage , modelInfo )
@@ -290,7 +290,7 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
290290 throw handleOpenAIError ( error , this . providerName )
291291 }
292292
293- return response . choices [ 0 ] ?. message . content || ""
293+ return response . choices ?. [ 0 ] ?. message . content || ""
294294 } catch ( error ) {
295295 if ( error instanceof Error ) {
296296 throw new Error ( `${ this . providerName } completion error: ${ error . message } ` )
@@ -373,15 +373,15 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
373373
374374 yield {
375375 type : "text" ,
376- text : response . choices [ 0 ] ?. message . content || "" ,
376+ text : response . choices ?. [ 0 ] ?. message . content || "" ,
377377 }
378378 yield this . processUsageMetrics ( response . usage )
379379 }
380380 }
381381
382382 private async * handleStreamResponse ( stream : AsyncIterable < OpenAI . Chat . Completions . ChatCompletionChunk > ) : ApiStream {
383383 for await ( const chunk of stream ) {
384- const delta = chunk . choices [ 0 ] ?. delta
384+ const delta = chunk . choices ?. [ 0 ] ?. delta
385385 if ( delta ?. content ) {
386386 yield {
387387 type : "text" ,
0 commit comments