Skip to content

Commit

Permalink
chore: Handle error in anthropic streaming response
Browse files Browse the repository at this point in the history
  • Loading branch information
narengogi committed Nov 11, 2024
1 parent 213273d commit 38bb170
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/providers/anthropic/chatComplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions src/providers/google-vertex-ai/chatComplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 38bb170

Please sign in to comment.