When the completion contains non-ASCII characters,
request.length actually represents the UTF-8 characters length and does not represent the correct Content-Length,
whereas in Helix, the Content-Length represents the byte size of the request.
For example, "你好,世界".length is 5, but its byte size is 15,.
We can use TextEncoder to convert the request to a Uint8Array and then get the length of the array, its represents the byte size of request.
When the completion contains non-ASCII characters,
request.length
actually represents the UTF-8 characters length and does not represent the correct Content-Length, whereas in Helix, theContent-Length
represents the byte size of the request.For example, "你好,世界".length is 5, but its byte size is 15,. We can use TextEncoder to convert the
request
to a Uint8Array and then get the length of the array, its represents the byte size ofrequest
.