Skip to content

Commit d3708ad

Browse files
authored
Merge branch 'main' into feature/add-qualifire-integration
2 parents a65f9d7 + c1c7e7d commit d3708ad

File tree

5 files changed

+46
-9
lines changed

5 files changed

+46
-9
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@portkey-ai/gateway",
3-
"version": "1.12.2",
3+
"version": "1.12.3",
44
"description": "A fast AI gateway by Portkey",
55
"repository": {
66
"type": "git",

src/handlers/handlerUtils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,7 @@ export function constructConfigFromRequestHeaders(
940940
vertexModelName: requestHeaders[`x-${POWERED_BY}-provider-model`],
941941
vertexBatchEndpoint:
942942
requestHeaders[`x-${POWERED_BY}-provider-batch-endpoint`],
943+
anthropicBeta: requestHeaders[`x-${POWERED_BY}-anthropic-beta`],
943944
};
944945

945946
const fireworksConfig = {

src/providers/bedrock/messages.ts

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -435,9 +435,9 @@ export const BedrockMessagesResponseTransform = (
435435
_gatewayRequestUrl: string,
436436
gatewayRequest: Params
437437
): MessagesResponse | ErrorResponse => {
438-
if (responseStatus !== 200 && 'error' in response) {
438+
if (responseStatus !== 200) {
439439
return (
440-
BedrockErrorResponseTransform(response) ||
440+
BedrockErrorResponseTransform(response as BedrockErrorResponse) ||
441441
generateInvalidProviderResponseError(response, BEDROCK)
442442
);
443443
}
@@ -513,6 +513,36 @@ const transformContentBlock = (
513513
return undefined;
514514
};
515515

516+
function createContentBlockStartEvent(
517+
parsedChunk: BedrockChatCompleteStreamChunk
518+
): RawContentBlockStartEvent {
519+
const contentBlockStartEvent: RawContentBlockStartEvent = JSON.parse(
520+
ANTHROPIC_CONTENT_BLOCK_START_EVENT
521+
);
522+
523+
if (parsedChunk.start?.toolUse && parsedChunk.start.toolUse.toolUseId) {
524+
contentBlockStartEvent.content_block = {
525+
type: 'tool_use',
526+
id: parsedChunk.start.toolUse.toolUseId,
527+
name: parsedChunk.start.toolUse.name,
528+
input: {},
529+
};
530+
} else if (parsedChunk.delta?.reasoningContent?.text) {
531+
contentBlockStartEvent.content_block = {
532+
type: 'thinking',
533+
thinking: '',
534+
signature: '',
535+
};
536+
} else if (parsedChunk.delta?.reasoningContent?.redactedContent) {
537+
contentBlockStartEvent.content_block = {
538+
type: 'redacted_thinking',
539+
data: parsedChunk.delta.reasoningContent.redactedContent,
540+
};
541+
}
542+
543+
return contentBlockStartEvent;
544+
}
545+
516546
export const BedrockConverseMessagesStreamChunkTransform = (
517547
responseChunk: string,
518548
fallbackId: string,
@@ -545,9 +575,8 @@ export const BedrockConverseMessagesStreamChunkTransform = (
545575
returnChunk += `event: content_block_stop\ndata: ${JSON.stringify(previousBlockStopEvent)}\n\n`;
546576
}
547577
streamState.currentContentBlockIndex = parsedChunk.contentBlockIndex;
548-
const contentBlockStartEvent: RawContentBlockStartEvent = JSON.parse(
549-
ANTHROPIC_CONTENT_BLOCK_START_EVENT
550-
);
578+
const contentBlockStartEvent: RawContentBlockStartEvent =
579+
createContentBlockStartEvent(parsedChunk);
551580
contentBlockStartEvent.index = parsedChunk.contentBlockIndex;
552581
returnChunk += `event: content_block_start\ndata: ${JSON.stringify(contentBlockStartEvent)}\n\n`;
553582
const contentBlockDeltaEvent = transformContentBlock(parsedChunk);

src/providers/google-vertex-ai/api.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,23 @@ export const GoogleApiConfig: ProviderAPIConfig = {
6262
}
6363
return `https://${vertexRegion}-aiplatform.googleapis.com`;
6464
},
65-
headers: async ({ c, providerOptions }) => {
65+
headers: async ({ c, providerOptions, gatewayRequestBody }) => {
6666
const { apiKey, vertexServiceAccountJson } = providerOptions;
6767
let authToken = apiKey;
6868
if (vertexServiceAccountJson) {
6969
authToken = await getAccessToken(c, vertexServiceAccountJson);
7070
}
7171

72+
const anthropicBeta =
73+
providerOptions?.['anthropicBeta'] ??
74+
gatewayRequestBody?.['anthropic_beta'];
75+
7276
return {
7377
'Content-Type': 'application/json',
7478
Authorization: `Bearer ${authToken}`,
79+
...(anthropicBeta && {
80+
'anthropic-beta': anthropicBeta,
81+
}),
7582
};
7683
},
7784
getEndpoint: ({

0 commit comments

Comments
 (0)