Skip to content

Commit c7a2951

Browse files
authored
Merge pull request #1284 from Portkey-AI/fix/anthropic-tools-index-streaming
fix anthropic streaming tool index increment
2 parents da07600 + 7cb9360 commit c7a2951

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/providers/anthropic/chatComplete.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,9 @@ export const AnthropicChatCompleteStreamChunkTransform: (
606606
streamState,
607607
strictOpenAiCompliance
608608
) => {
609+
if (streamState.toolIndex == undefined) {
610+
streamState.toolIndex = -1;
611+
}
609612
let chunk = responseChunk.trim();
610613
if (
611614
chunk.startsWith('event: ping') ||
@@ -724,9 +727,7 @@ export const AnthropicChatCompleteStreamChunkTransform: (
724727
parsedChunk.type === 'content_block_start' &&
725728
parsedChunk.content_block?.type === 'tool_use';
726729
if (isToolBlockStart) {
727-
streamState.toolIndex = streamState.toolIndex
728-
? streamState.toolIndex + 1
729-
: 0;
730+
streamState.toolIndex = streamState.toolIndex + 1;
730731
}
731732
const isToolBlockDelta: boolean =
732733
parsedChunk.type === 'content_block_delta' &&

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,9 @@ export const VertexAnthropicChatCompleteStreamChunkTransform: (
792792
streamState,
793793
strictOpenAiCompliance
794794
) => {
795+
if (streamState.toolIndex == undefined) {
796+
streamState.toolIndex = -1;
797+
}
795798
let chunk = responseChunk.trim();
796799

797800
if (
@@ -899,9 +902,7 @@ export const VertexAnthropicChatCompleteStreamChunkTransform: (
899902
parsedChunk.type === 'content_block_start' &&
900903
parsedChunk.content_block?.type === 'tool_use';
901904
if (isToolBlockStart) {
902-
streamState.toolIndex = streamState.toolIndex
903-
? streamState.toolIndex + 1
904-
: 0;
905+
streamState.toolIndex = streamState.toolIndex + 1;
905906
}
906907
const isToolBlockDelta: boolean =
907908
parsedChunk.type === 'content_block_delta' &&

0 commit comments

Comments
 (0)