File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -97,7 +97,12 @@ export async function handleOpenAIStream({
9797 streamOptions . include_usage = true
9898 openaiBody . stream_options = streamOptions
9999
100- // Remove fields that OpenAI might not accept
100+ // Transform max_tokens to max_completion_tokens
101+ openaiBody . max_completion_tokens = openaiBody . max_tokens
102+ delete ( openaiBody as any ) . max_tokens
103+
104+ // Remove fields that OpenAI doesn't support
105+ delete ( openaiBody as any ) . stop
101106 delete ( openaiBody as any ) . usage
102107 delete ( openaiBody as any ) . provider
103108 delete ( openaiBody as any ) . transforms
@@ -113,10 +118,10 @@ export async function handleOpenAIStream({
113118 } )
114119
115120 if ( ! response . ok ) {
116- throw new Error ( `OpenAI API error: ${ response . status } ${ response . statusText } ` )
121+ throw new Error ( `OpenAI API error: ${ response . status } ${ response . statusText } ${ await response . text ( ) } ` )
117122 }
118123
119- const reader = response . body ?. getReader ( )
124+ const reader = response . body ?. getReader ?. ( )
120125 if ( ! reader ) {
121126 throw new Error ( 'Failed to get response reader' )
122127 }
You can’t perform that action at this time.
0 commit comments