diff --git a/src/providers/anthropic/chatComplete.ts b/src/providers/anthropic/chatComplete.ts index c9546bad..f7a281a8 100644 --- a/src/providers/anthropic/chatComplete.ts +++ b/src/providers/anthropic/chatComplete.ts @@ -364,6 +364,7 @@ export interface AnthropicChatCompleteStreamResponse { cache_read_input_tokens?: number; }; }; + error?: AnthropicErrorObject; } export const AnthropicErrorResponseTransform: ( @@ -484,6 +485,29 @@ export const AnthropicChatCompleteStreamChunkTransform: ( chunk = chunk.trim(); const parsedChunk: AnthropicChatCompleteStreamResponse = JSON.parse(chunk); + + if (parsedChunk.type === 'error' && parsedChunk.error) { + return ( + `data: ${JSON.stringify({ + id: fallbackId, + object: 'chat.completion.chunk', + created: Math.floor(Date.now() / 1000), + model: '', + provider: ANTHROPIC, + choices: [ + { + finish_reason: parsedChunk.error.type, + delta: { + content: '', + }, + }, + ], + })}` + + '\n\n' + + '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 ac55a3a2..0e7e153c 100644 --- a/src/providers/google-vertex-ai/chatComplete.ts +++ b/src/providers/google-vertex-ai/chatComplete.ts @@ -928,6 +928,28 @@ export const VertexAnthropicChatCompleteStreamChunkTransform: ( const parsedChunk: AnthropicChatCompleteStreamResponse = JSON.parse(chunk); + if (parsedChunk.type === 'error' && parsedChunk.error) { + return ( + `data: ${JSON.stringify({ + id: fallbackId, + object: 'chat.completion.chunk', + created: Math.floor(Date.now() / 1000), + model: '', + provider: GOOGLE_VERTEX_AI, + choices: [ + { + finish_reason: parsedChunk.error.type, + delta: { + content: '', + }, + }, + ], + })}` + + '\n\n' + + 'data: [DONE]\n\n' + ); + } + if ( parsedChunk.type === 'content_block_start' && parsedChunk.content_block?.type === 'text' diff --git a/src/providers/segmind/api.ts b/src/providers/segmind/api.ts index ffa3af6f..568701a3 100644 --- a/src/providers/segmind/api.ts +++ b/src/providers/segmind/api.ts @@ -1,6 +1,6 @@ import { ProviderAPIConfig } from '../types'; -const StabilityAIAPIConfig: ProviderAPIConfig = { +const SegmindAIAPIConfig: ProviderAPIConfig = { getBaseURL: () => 'https://api.segmind.com/v1', headers: ({ providerOptions }) => { return { 'x-api-key': `${providerOptions.apiKey}` }; @@ -10,4 +10,4 @@ const StabilityAIAPIConfig: ProviderAPIConfig = { }, }; -export default StabilityAIAPIConfig; +export default SegmindAIAPIConfig; diff --git a/src/providers/segmind/index.ts b/src/providers/segmind/index.ts index ee894df8..f1a0e1f9 100644 --- a/src/providers/segmind/index.ts +++ b/src/providers/segmind/index.ts @@ -1,12 +1,12 @@ import { ProviderConfigs } from '../types'; -import SegmindAPIConfig from './api'; +import SegmindAIAPIConfig from './api'; import { SegmindImageGenerateConfig, SegmindImageGenerateResponseTransform, } from './imageGenerate'; const SegmindConfig: ProviderConfigs = { - api: SegmindAPIConfig, + api: SegmindAIAPIConfig, imageGenerate: SegmindImageGenerateConfig, responseTransforms: { imageGenerate: SegmindImageGenerateResponseTransform,