Skip to content

Commit 7cb9360

Browse files
narengogilucgagan
andcommitted
fix anthropic streaming tool index increment
Co-authored-by: lucgagan <[email protected]>
1 parent cd4ca6c commit 7cb9360

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
@@ -786,6 +786,9 @@ export const VertexAnthropicChatCompleteStreamChunkTransform: (
786786
streamState,
787787
strictOpenAiCompliance
788788
) => {
789+
if (streamState.toolIndex == undefined) {
790+
streamState.toolIndex = -1;
791+
}
789792
let chunk = responseChunk.trim();
790793

791794
if (
@@ -893,9 +896,7 @@ export const VertexAnthropicChatCompleteStreamChunkTransform: (
893896
parsedChunk.type === 'content_block_start' &&
894897
parsedChunk.content_block?.type === 'tool_use';
895898
if (isToolBlockStart) {
896-
streamState.toolIndex = streamState.toolIndex
897-
? streamState.toolIndex + 1
898-
: 0;
899+
streamState.toolIndex = streamState.toolIndex + 1;
899900
}
900901
const isToolBlockDelta: boolean =
901902
parsedChunk.type === 'content_block_delta' &&

0 commit comments

Comments
 (0)