File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed
Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -32,18 +32,24 @@ export class OpenAiHandler implements ApiHandler {
3232 }
3333 }
3434
35+ // Include stream_options for OpenAI Compatible providers if the checkbox is checked
3536 async * createMessage ( systemPrompt : string , messages : Anthropic . Messages . MessageParam [ ] ) : ApiStream {
3637 const openAiMessages : OpenAI . Chat . ChatCompletionMessageParam [ ] = [
3738 { role : "system" , content : systemPrompt } ,
3839 ...convertToOpenAiMessages ( messages ) ,
3940 ]
40- const stream = await this . client . chat . completions . create ( {
41+ const requestOptions : OpenAI . Chat . ChatCompletionCreateParams = {
4142 model : this . options . openAiModelId ?? "" ,
4243 messages : openAiMessages ,
4344 temperature : 0 ,
4445 stream : true ,
45- stream_options : { include_usage : true } ,
46- } )
46+ }
47+
48+ if ( this . options . includeStreamOptions ) {
49+ requestOptions . stream_options = { include_usage : true }
50+ }
51+
52+ const stream = await this . client . chat . completions . create ( requestOptions )
4753 for await ( const chunk of stream ) {
4854 const delta = chunk . choices [ 0 ] ?. delta
4955 if ( delta ?. content ) {
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ export interface ApiHandlerOptions {
3434 openAiNativeApiKey ?: string
3535 azureApiVersion ?: string
3636 openRouterUseMiddleOutTransform ?: boolean
37+ includeStreamOptions ?: boolean
3738}
3839
3940export type ApiConfiguration = ApiHandlerOptions & {
You can’t perform that action at this time.
0 commit comments