Spaces:
Paused
Paused
Download src/lib/translator/streamTransform.ts from igorkurgin/omniroute: direct link, hf CLI and curl.
- Browser
- Download file 794 Bytes
-
https://huggingface.co/spaces/igorkurgin/omniroute/resolve/main/src/lib/translator/streamTransform.ts
- Command line
-
hf download hf://spaces/igorkurgin/omniroute/src/lib/translator/streamTransform.ts
-
curl -L -o streamTransform.ts https://huggingface.co/spaces/igorkurgin/omniroute/resolve/main/src/lib/translator/streamTransform.ts
794 Bytes
| import { createResponsesApiTransformStream } from "@omniroute/open-sse/transformer/responsesTransformer.ts"; | |
| export async function transformChatCompletionSseToResponses(rawSse: string): Promise<string> { | |
| const encoder = new TextEncoder(); | |
| const decoder = new TextDecoder(); | |
| const inputStream = new ReadableStream<Uint8Array>({ | |
| start(controller) { | |
| controller.enqueue(encoder.encode(rawSse)); | |
| controller.close(); | |
| }, | |
| }); | |
| const outputStream = inputStream.pipeThrough(createResponsesApiTransformStream()); | |
| const reader = outputStream.getReader(); | |
| let output = ""; | |
| while (true) { | |
| const { value, done } = await reader.read(); | |
| if (done) break; | |
| output += decoder.decode(value, { stream: true }); | |
| } | |
| output += decoder.decode(); | |
| return output; | |
| } | |