From acf008da7f13aad9948470cc35e68affbee204b0 Mon Sep 17 00:00:00 2001 From: Shaun Maher Date: Tue, 30 Jan 2024 15:26:05 +1100 Subject: [PATCH] Specify a "Content-Type" header in response streams so that Cloudflare / cloudflared (tunnel) know to stream the responses rather than buffer them. --- src/features/chat/chat-services/chat-api-data.ts | 4 +++- src/features/chat/chat-services/chat-api-simple.ts | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/features/chat/chat-services/chat-api-data.ts b/src/features/chat/chat-services/chat-api-data.ts index 8cd2481c3..33f3345fe 100644 --- a/src/features/chat/chat-services/chat-api-data.ts +++ b/src/features/chat/chat-services/chat-api-data.ts @@ -95,7 +95,9 @@ export const ChatAPIData = async (props: PromptGPTProps) => { }, }); - return new StreamingTextResponse(stream); + return new StreamingTextResponse(stream, { + headers: {"Content-Type": "text/event-stream"}, + }); } catch (e: unknown) { if (e instanceof Error) { return new Response(e.message, { diff --git a/src/features/chat/chat-services/chat-api-simple.ts b/src/features/chat/chat-services/chat-api-simple.ts index df855a1e3..4a80d628e 100644 --- a/src/features/chat/chat-services/chat-api-simple.ts +++ b/src/features/chat/chat-services/chat-api-simple.ts @@ -49,7 +49,9 @@ export const ChatAPISimple = async (props: PromptGPTProps) => { }); }, }); - return new StreamingTextResponse(stream); + return new StreamingTextResponse(stream, { + headers: {"Content-Type": "text/event-stream"}, + }); } catch (e: unknown) { if (e instanceof Error) { return new Response(e.message, {