From cd6cc76a46c5ebaba7045b1e2c8addb625c15a89 Mon Sep 17 00:00:00 2001 From: user Date: Wed, 22 Jan 2025 15:23:17 +0000 Subject: [PATCH] Attempt to improve the o1 timeout hack --- src/proxy/openai.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/proxy/openai.ts b/src/proxy/openai.ts index 5f43992..df918e6 100644 --- a/src/proxy/openai.ts +++ b/src/proxy/openai.ts @@ -112,8 +112,7 @@ const openaiResponseHandler: ProxyResHandlerWithBody = async ( const interval = (req as any)._keepAliveInterval if (interval) { clearInterval(interval); - const responseJson = JSON.stringify(body); - res.write(responseJson.substring(1)); + res.write(JSON.stringify(body)); res.end(); return; } @@ -191,13 +190,11 @@ const setupChunkedTransfer: RequestHandler = (req, res, next) => { 'Transfer-Encoding': 'chunked' }); - res.write('{'); - // Higher values are required - otherwise Cloudflare will buffer and not pass // the separate chunks, which means that a >100s response will get terminated anyway const keepAlive = setInterval(() => { res.write(' '.repeat(4096)); - }, 49_000); + }, 48_000); (req as any)._keepAliveInterval = keepAlive; }