@@ -299,47 +299,41 @@ export class BetaRunner extends BaseRunner<BetaRunnerTypes> {
299299 : system ;
300300 }
301301
302+ const thinkingConfig = this . toAnthropicThinkingConfig (
303+ request . config ?. thinking
304+ ) as BetaMessageCreateParams [ 'thinking' ] | undefined ;
305+
306+ const { thinking : defaultThinkingConfig , ...restConfig } =
307+ request . config || { } ;
308+
302309 const body : BetaMessageCreateParamsNonStreaming = {
303310 model : mappedModelName ,
304311 max_tokens :
305312 request . config ?. maxOutputTokens ?? this . DEFAULT_MAX_OUTPUT_TOKENS ,
306313 messages,
307- betas : BETA_APIS ,
314+ system : betaSystem ,
315+ stop_sequences : request . config ?. stopSequences ,
316+ temperature : request . config ?. temperature ,
317+ top_k : request . config ?. topK ,
318+ top_p : request . config ?. topP ,
319+ tool_choice : request . config ?. tool_choice ,
320+ metadata : request . config ?. metadata ,
321+ tools : request . tools ?. map ( ( tool ) => this . toAnthropicTool ( tool ) ) ,
322+ thinking :
323+ ( defaultThinkingConfig as BetaMessageCreateParams [ 'thinking' ] ) ??
324+ thinkingConfig ,
325+ output_format : this . isStructuredOutputEnabled ( request )
326+ ? {
327+ type : 'json_schema' ,
328+ schema : toAnthropicSchema ( request . output ! . schema ! ) ,
329+ }
330+ : undefined ,
331+ betas : Array . isArray ( request . config ?. betas )
332+ ? [ ...BETA_APIS , ...( request . config ?. betas ?? [ ] ) ]
333+ : [ ...BETA_APIS ] ,
334+ ...restConfig ,
308335 } ;
309336
310- if ( betaSystem !== undefined ) body . system = betaSystem ;
311- if ( request . config ?. stopSequences !== undefined )
312- body . stop_sequences = request . config . stopSequences ;
313- if ( request . config ?. temperature !== undefined )
314- body . temperature = request . config . temperature ;
315- if ( request . config ?. topK !== undefined ) body . top_k = request . config . topK ;
316- if ( request . config ?. topP !== undefined ) body . top_p = request . config . topP ;
317- if ( request . config ?. tool_choice !== undefined ) {
318- body . tool_choice = request . config
319- . tool_choice as BetaMessageCreateParams [ 'tool_choice' ] ;
320- }
321- if ( request . config ?. metadata !== undefined ) {
322- body . metadata = request . config
323- . metadata as BetaMessageCreateParams [ 'metadata' ] ;
324- }
325- if ( request . tools ) {
326- body . tools = request . tools . map ( ( tool ) => this . toAnthropicTool ( tool ) ) ;
327- }
328- const thinkingConfig = this . toAnthropicThinkingConfig (
329- request . config ?. thinking
330- ) ;
331- if ( thinkingConfig ) {
332- body . thinking = thinkingConfig as BetaMessageCreateParams [ 'thinking' ] ;
333- }
334-
335- // Apply structured output when model supports it and constrained output is requested
336- if ( this . isStructuredOutputEnabled ( request ) ) {
337- body . output_format = {
338- type : 'json_schema' ,
339- schema : toAnthropicSchema ( request . output ! . schema ! ) ,
340- } ;
341- }
342-
343337 return body ;
344338 }
345339
@@ -369,47 +363,42 @@ export class BetaRunner extends BaseRunner<BetaRunnerTypes> {
369363 ]
370364 : system ;
371365
366+ const thinkingConfig = this . toAnthropicThinkingConfig (
367+ request . config ?. thinking
368+ ) as BetaMessageCreateParams [ 'thinking' ] | undefined ;
369+
370+ const { thinking : defaultThinkingConfig , ...restConfig } =
371+ request . config || { } ;
372+
372373 const body : BetaMessageCreateParamsStreaming = {
373374 model : mappedModelName ,
374375 max_tokens :
375376 request . config ?. maxOutputTokens ?? this . DEFAULT_MAX_OUTPUT_TOKENS ,
376377 messages,
377378 stream : true ,
378- betas : BETA_APIS ,
379+ system : betaSystem ,
380+ stop_sequences : request . config ?. stopSequences ,
381+ temperature : request . config ?. temperature ,
382+ top_k : request . config ?. topK ,
383+ top_p : request . config ?. topP ,
384+ tool_choice : request . config ?. tool_choice ,
385+ metadata : request . config ?. metadata ,
386+ tools : request . tools ?. map ( ( tool ) => this . toAnthropicTool ( tool ) ) ,
387+ thinking :
388+ ( defaultThinkingConfig as BetaMessageCreateParams [ 'thinking' ] ) ??
389+ thinkingConfig ,
390+ output_format : this . isStructuredOutputEnabled ( request )
391+ ? {
392+ type : 'json_schema' ,
393+ schema : toAnthropicSchema ( request . output ! . schema ! ) ,
394+ }
395+ : undefined ,
396+ betas : Array . isArray ( request . config ?. betas )
397+ ? [ ...BETA_APIS , ...( request . config ?. betas ?? [ ] ) ]
398+ : [ ...BETA_APIS ] ,
399+ ...restConfig ,
379400 } ;
380401
381- if ( betaSystem !== undefined ) body . system = betaSystem ;
382- if ( request . config ?. stopSequences !== undefined )
383- body . stop_sequences = request . config . stopSequences ;
384- if ( request . config ?. temperature !== undefined )
385- body . temperature = request . config . temperature ;
386- if ( request . config ?. topK !== undefined ) body . top_k = request . config . topK ;
387- if ( request . config ?. topP !== undefined ) body . top_p = request . config . topP ;
388- if ( request . config ?. tool_choice !== undefined ) {
389- body . tool_choice = request . config
390- . tool_choice as BetaMessageCreateParams [ 'tool_choice' ] ;
391- }
392- if ( request . config ?. metadata !== undefined ) {
393- body . metadata = request . config
394- . metadata as BetaMessageCreateParams [ 'metadata' ] ;
395- }
396- if ( request . tools ) {
397- body . tools = request . tools . map ( ( tool ) => this . toAnthropicTool ( tool ) ) ;
398- }
399- const thinkingConfig = this . toAnthropicThinkingConfig (
400- request . config ?. thinking
401- ) ;
402- if ( thinkingConfig ) {
403- body . thinking = thinkingConfig as BetaMessageCreateParams [ 'thinking' ] ;
404- }
405-
406- // Apply structured output when model supports it and constrained output is requested
407- if ( this . isStructuredOutputEnabled ( request ) ) {
408- body . output_format = {
409- type : 'json_schema' ,
410- schema : toAnthropicSchema ( request . output ! . schema ! ) ,
411- } ;
412- }
413402 return body ;
414403 }
415404
0 commit comments