Skip to content

Commit d55a6c7

Browse files
authored
Merge branch 'main' into featherless-provider
2 parents cd3a24a + d7a2686 commit d55a6c7

File tree

3 files changed

+43
-14
lines changed

3 files changed

+43
-14
lines changed

src/providers/anthropic/chatComplete.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,16 @@ interface AnthropicTool extends PromptCache {
4343
interface AnthropicToolResultContentItem {
4444
type: 'tool_result';
4545
tool_use_id: string;
46-
content?: string;
46+
content?:
47+
| {
48+
type: string;
49+
text?: string;
50+
cache_control?: {
51+
type: string;
52+
ttl?: number;
53+
};
54+
}[]
55+
| string;
4756
}
4857

4958
interface AnthropicBase64ImageContentItem {
@@ -138,6 +147,9 @@ const transformAssistantMessage = (msg: Message): AnthropicMessage => {
138147
input: toolCall.function.arguments?.length
139148
? JSON.parse(toolCall.function.arguments)
140149
: {},
150+
...(toolCall.cache_control && {
151+
cache_control: toolCall.cache_control,
152+
}),
141153
});
142154
});
143155
}
@@ -155,7 +167,7 @@ const transformToolMessage = (msg: Message): AnthropicMessage => {
155167
{
156168
type: 'tool_result',
157169
tool_use_id,
158-
content: msg.content as string,
170+
content: msg.content,
159171
},
160172
],
161173
};
@@ -250,6 +262,9 @@ export const AnthropicChatCompleteConfig: ProviderConfig = {
250262

251263
if (msg.role === 'assistant') {
252264
messages.push(transformAssistantMessage(msg));
265+
} else if (msg.role === 'tool') {
266+
// even though anthropic supports images in tool results, openai doesn't support it yet
267+
messages.push(transformToolMessage(msg));
253268
} else if (
254269
msg.content &&
255270
typeof msg.content === 'object' &&
@@ -275,9 +290,6 @@ export const AnthropicChatCompleteConfig: ProviderConfig = {
275290
}
276291
});
277292
messages.push(transformedMessage as AnthropicMessage);
278-
} else if (msg.role === 'tool') {
279-
// even though anthropic supports images in tool results, openai doesn't support it yet
280-
messages.push(transformToolMessage(msg));
281293
} else {
282294
messages.push({
283295
role: msg.role,

src/providers/bedrock/utils.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,26 @@ export const populateHyperParameters = (value: FinetuneRequest) => {
407407

408408
export const getInferenceProfile = async (
409409
inferenceProfileIdentifier: string,
410-
awsRegion: string,
411-
awsAccessKeyId: string,
412-
awsSecretAccessKey: string,
413-
awsSessionToken?: string
410+
providerOptions: Options,
411+
c: Context
414412
) => {
413+
if (providerOptions.awsAuthType === 'assumedRole') {
414+
const { accessKeyId, secretAccessKey, sessionToken } =
415+
(await getAssumedRoleCredentials(
416+
c,
417+
providerOptions.awsRoleArn || '',
418+
providerOptions.awsExternalId || '',
419+
providerOptions.awsRegion || ''
420+
)) || {};
421+
providerOptions.awsAccessKeyId = accessKeyId;
422+
providerOptions.awsSecretAccessKey = secretAccessKey;
423+
providerOptions.awsSessionToken = sessionToken;
424+
}
425+
426+
const awsRegion = providerOptions.awsRegion || 'us-east-1';
427+
const awsAccessKeyId = providerOptions.awsAccessKeyId || '';
428+
const awsSecretAccessKey = providerOptions.awsSecretAccessKey || '';
429+
const awsSessionToken = providerOptions.awsSessionToken || '';
415430
const url = `https://bedrock.${awsRegion}.amazonaws.com/inference-profiles/${encodeURIComponent(decodeURIComponent(inferenceProfileIdentifier))}`;
416431

417432
const headers = await generateAWSHeaders(
@@ -463,10 +478,8 @@ export const getFoundationModelFromInferenceProfile = async (
463478

464479
const inferenceProfile = await getInferenceProfile(
465480
inferenceProfileIdentifier || '',
466-
providerOptions.awsRegion || '',
467-
providerOptions.awsAccessKeyId || '',
468-
providerOptions.awsSecretAccessKey || '',
469-
providerOptions.awsSessionToken || ''
481+
{ ...providerOptions },
482+
c
470483
);
471484

472485
// modelArn is always like arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-v2:1

src/providers/groq/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import { GROQ } from '../../globals';
1010

1111
const GroqConfig: ProviderConfigs = {
1212
api: GroqAPIConfig,
13-
chatComplete: chatCompleteParams(['logprobs', 'logits_bias', 'top_logprobs']),
13+
chatComplete: chatCompleteParams(
14+
['logprobs', 'logits_bias', 'top_logprobs'],
15+
undefined,
16+
{ service_tier: { param: 'service_tier', required: false } }
17+
),
1418
createTranscription: {},
1519
createTranslation: {},
1620
createSpeech: createSpeechParams([]),

0 commit comments

Comments
 (0)