const reader = response.body.getReader();
const decoder = new TextDecoder('utf-8');
while (!done) {
const { value, done: readerDone } = await reader.read();
if (value) {
const char = decoder.decode(value);
console.log(char);
}
}
代码如上,有时候打印出来的 char 为:
data: {"id":"chatcmpl-7Y79egENb17GOU20IaW5KgJJhbf4M","object":"chat.completion.chunk","created":1688365010,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"chatcmpl-7Y79egEN
图示: https://i.imgur.com/P1YQs4q.png
也就是从"id"中间被切断了,导致内容少 1 到 2 个字。
请问有啥可改进的方法吗?