From 38bb1704139e8251a92fcc9bf888cfdc38c4f867 Mon Sep 17 00:00:00 2001 From: Narendranath Gogineni Date: Mon, 11 Nov 2024 15:51:44 +0530 Subject: [PATCH] chore: Handle error in anthropic streaming response --- src/providers/anthropic/chatComplete.ts | 3 +++ src/providers/google-vertex-ai/chatComplete.ts | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/providers/anthropic/chatComplete.ts b/src/providers/anthropic/chatComplete.ts index 6113ad821..a6ac100e2 100644 --- a/src/providers/anthropic/chatComplete.ts +++ b/src/providers/anthropic/chatComplete.ts @@ -480,6 +480,9 @@ export const AnthropicChatCompleteStreamChunkTransform: ( chunk = chunk.trim(); const parsedChunk: AnthropicChatCompleteStreamResponse = JSON.parse(chunk); + + if (parsedChunk.type === 'error') return 'data: [DONE]\n\n'; + if ( parsedChunk.type === 'content_block_start' && parsedChunk.content_block?.type === 'text' diff --git a/src/providers/google-vertex-ai/chatComplete.ts b/src/providers/google-vertex-ai/chatComplete.ts index 23b0d48fd..e2f8f651c 100644 --- a/src/providers/google-vertex-ai/chatComplete.ts +++ b/src/providers/google-vertex-ai/chatComplete.ts @@ -894,6 +894,8 @@ export const VertexAnthropicChatCompleteStreamChunkTransform: ( const parsedChunk: AnthropicChatCompleteStreamResponse = JSON.parse(chunk); + if (parsedChunk.type === 'error') return 'data: [DONE]\n\n'; + if ( parsedChunk.type === 'content_block_start' && parsedChunk.content_block?.type === 'text'