File tree Expand file tree Collapse file tree 4 files changed +41
-19
lines changed Expand file tree Collapse file tree 4 files changed +41
-19
lines changed Original file line number Diff line number Diff line change @@ -362,11 +362,15 @@ export const AnthropicChatCompleteConfig: ProviderConfig = {
362
362
cache_control : { type : 'ephemeral' } ,
363
363
} ) ,
364
364
} ) ;
365
- } else if ( tool . computer ) {
365
+ } else if ( tool . type ) {
366
+ const toolOptions = tool [ tool . type ] ;
366
367
tools . push ( {
367
- ...tool . computer ,
368
- name : 'computer' ,
369
- type : tool . computer . name ,
368
+ ...( toolOptions && { ...toolOptions } ) ,
369
+ name : tool . type ,
370
+ type : toolOptions ?. name ,
371
+ ...( tool . cache_control && {
372
+ cache_control : { type : 'ephemeral' } ,
373
+ } ) ,
370
374
} ) ;
371
375
}
372
376
} ) ;
Original file line number Diff line number Diff line change @@ -315,13 +315,15 @@ export const BedrockConverseChatCompleteConfig: ProviderConfig = {
315
315
| { cachePoint : { type : string } }
316
316
> = [ ] ;
317
317
params . tools ?. forEach ( ( tool ) => {
318
- tools . push ( {
319
- toolSpec : {
320
- name : tool . function . name ,
321
- description : tool . function . description ,
322
- inputSchema : { json : tool . function . parameters } ,
323
- } ,
324
- } ) ;
318
+ if ( tool . function ) {
319
+ tools . push ( {
320
+ toolSpec : {
321
+ name : tool . function . name ,
322
+ description : tool . function . description ,
323
+ inputSchema : { json : tool . function . parameters } ,
324
+ } ,
325
+ } ) ;
326
+ }
325
327
if ( tool . cache_control && ! canBeAmazonModel ) {
326
328
tools . push ( {
327
329
cachePoint : {
@@ -353,7 +355,8 @@ export const BedrockConverseChatCompleteConfig: ProviderConfig = {
353
355
}
354
356
}
355
357
}
356
- return { ...toolConfig , toolChoice } ;
358
+ // TODO: split this into two provider options, one for tools and one for toolChoice
359
+ return tools . length ? { ...toolConfig , toolChoice } : null ;
357
360
} ,
358
361
} ,
359
362
guardrailConfig : {
Original file line number Diff line number Diff line change 8
8
BedrockConverseAnthropicChatCompletionsParams ,
9
9
BedrockConverseCohereChatCompletionsParams ,
10
10
} from './chatComplete' ;
11
- import { Options } from '../../types/requestBody' ;
11
+ import { Options , Tool } from '../../types/requestBody' ;
12
12
import { GatewayError } from '../../errors/GatewayError' ;
13
13
import { BedrockFinetuneRecord , BedrockInferenceProfile } from './types' ;
14
14
import { FinetuneRequest } from '../types' ;
@@ -137,6 +137,25 @@ export const transformAnthropicAdditionalModelRequestFields = (
137
137
additionalModelRequestFields [ 'anthropic_beta' ] = params [ 'anthropic_beta' ] ;
138
138
}
139
139
}
140
+ if ( params . tools && params . tools . length ) {
141
+ const anthropicTools : any [ ] = [ ] ;
142
+ params . tools . forEach ( ( tool : Tool ) => {
143
+ if ( tool . type !== 'function' ) {
144
+ const toolOptions = tool [ tool . type ] ;
145
+ anthropicTools . push ( {
146
+ ...( toolOptions && { ...toolOptions } ) ,
147
+ name : tool . type ,
148
+ type : toolOptions ?. name ,
149
+ ...( tool . cache_control && {
150
+ cache_control : { type : 'ephemeral' } ,
151
+ } ) ,
152
+ } ) ;
153
+ }
154
+ } ) ;
155
+ if ( anthropicTools . length ) {
156
+ additionalModelRequestFields [ 'tools' ] = anthropicTools ;
157
+ }
158
+ }
140
159
return additionalModelRequestFields ;
141
160
} ;
142
161
Original file line number Diff line number Diff line change @@ -361,12 +361,8 @@ export interface Tool extends PromptCache {
361
361
type : string ;
362
362
/** A description of the function. */
363
363
function : Function ;
364
- computer ?: {
365
- name : string ;
366
- display_width_px : number ;
367
- display_height_px : number ;
368
- display_number : number ;
369
- } ;
364
+ // this is used to support tools like computer, web_search, etc.
365
+ [ key : string ] : any ;
370
366
}
371
367
372
368
/**
You can’t perform that action at this time.
0 commit comments