fixes kobold content-encoding

This commit is contained in:
nai-degen 2023-04-10 00:53:27 -07:00 committed by nai-degen
parent 14c890f268
commit 91cba67650
1 changed files with 15 additions and 1 deletions

View File

@ -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));
}
});
};