UNPKG

@lobehub/chat

Version:

Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.

26 lines (20 loc) 865 B
import { InvokeModelWithResponseStreamResponse } from '@aws-sdk/client-bedrock-runtime'; import { nanoid } from '@/utils/uuid'; import { ChatStreamCallbacks } from '../../../types'; import { transformAnthropicStream } from '../anthropic'; import { StreamContext, createCallbacksTransformer, createSSEProtocolTransformer, } from '../protocol'; import { createBedrockStream } from './common'; export const AWSBedrockClaudeStream = ( res: InvokeModelWithResponseStreamResponse | ReadableStream, cb?: ChatStreamCallbacks, ): ReadableStream<string> => { const streamStack: StreamContext = { id: 'chat_' + nanoid() }; const stream = res instanceof ReadableStream ? res : createBedrockStream(res); return stream .pipeThrough(createSSEProtocolTransformer(transformAnthropicStream, streamStack)) .pipeThrough(createCallbacksTransformer(cb)); };