UNPKG

llmatic

Version:

Use self-hosted LLMs with an OpenAI compatible API

21 lines (18 loc) 580 B
/* eslint-disable @typescript-eslint/naming-convention */ import type { FastifyReply } from "fastify"; export class SseHelper { sse(reply: FastifyReply, data: unknown) { if (!reply.raw.headersSent) { const headers = { "Content-Type": "text/event-stream", Connection: "keep-alive", "Cache-Control": "no-cache", }; reply.raw.writeHead(200, headers); } const normalizedData = typeof data === "string" ? data : JSON.stringify(data); const payload = `data: ${normalizedData}\n\n`; reply.raw.write(payload); } }