Skip to content

Commit b8ecbc6

Browse files
authored
Merge branch 'main' into feat/ft-batch-improvements
2 parents a9dd0f9 + d8c2358 commit b8ecbc6

File tree

4 files changed

+41
-19
lines changed

4 files changed

+41
-19
lines changed

src/providers/anthropic/chatComplete.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,15 @@ export const AnthropicChatCompleteConfig: ProviderConfig = {
362362
cache_control: { type: 'ephemeral' },
363363
}),
364364
});
365-
} else if (tool.computer) {
365+
} else if (tool.type) {
366+
const toolOptions = tool[tool.type];
366367
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+
}),
370374
});
371375
}
372376
});

src/providers/bedrock/chatComplete.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,15 @@ export const BedrockConverseChatCompleteConfig: ProviderConfig = {
315315
| { cachePoint: { type: string } }
316316
> = [];
317317
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+
}
325327
if (tool.cache_control && !canBeAmazonModel) {
326328
tools.push({
327329
cachePoint: {
@@ -353,7 +355,8 @@ export const BedrockConverseChatCompleteConfig: ProviderConfig = {
353355
}
354356
}
355357
}
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;
357360
},
358361
},
359362
guardrailConfig: {

src/providers/bedrock/utils.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
BedrockConverseAnthropicChatCompletionsParams,
99
BedrockConverseCohereChatCompletionsParams,
1010
} from './chatComplete';
11-
import { Options } from '../../types/requestBody';
11+
import { Options, Tool } from '../../types/requestBody';
1212
import { GatewayError } from '../../errors/GatewayError';
1313
import { BedrockFinetuneRecord, BedrockInferenceProfile } from './types';
1414
import { FinetuneRequest } from '../types';
@@ -137,6 +137,25 @@ export const transformAnthropicAdditionalModelRequestFields = (
137137
additionalModelRequestFields['anthropic_beta'] = params['anthropic_beta'];
138138
}
139139
}
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+
}
140159
return additionalModelRequestFields;
141160
};
142161

src/types/requestBody.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,8 @@ export interface Tool extends PromptCache {
361361
type: string;
362362
/** A description of the function. */
363363
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;
370366
}
371367

372368
/**

0 commit comments

Comments
 (0)