From 91cba67650822ebbb06c3f9d91eeb8d77037c346 Mon Sep 17 00:00:00 2001 From: nai-degen <44111-khanon@users.noreply.gitgud.io> Date: Mon, 10 Apr 2023 00:53:27 -0700 Subject: [PATCH] fixes kobold content-encoding --- src/proxy/kobold.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/proxy/kobold.ts b/src/proxy/kobold.ts index 63b548c..f87f5ce 100644 --- a/src/proxy/kobold.ts +++ b/src/proxy/kobold.ts @@ -86,8 +86,22 @@ const handleProxiedResponse = async ( const koboldResponse = { results: [{ text: response.choices[0].message.content }], + model: response.model, }; - res.status(200).json(koboldResponse); + + // Because we have decompressed the OpenAI response, we need to re-compress it + // before sending it to the client. + if (contentEncoding === "gzip") { + res.set("Content-Encoding", "gzip"); + res.send(await util.promisify(zlib.gzip)(JSON.stringify(koboldResponse))); + } else if (contentEncoding === "deflate") { + res.set("Content-Encoding", "deflate"); + res.send( + await util.promisify(zlib.deflate)(JSON.stringify(koboldResponse)) + ); + } else { + res.send(JSON.stringify(koboldResponse)); + } }); };