增加fetchEventSource里面的回调函数的注释

上级 8b7cde54
......@@ -90,20 +90,20 @@ export default {
'Content-Type': 'application/json'
},
body: JSON.stringify(body),
// 建立连接后立即执行
onopen: (response) => {
dialog.text = '';
},
// 接收到消息时执行
onmessage: (msg) => {
if (msg.data === '[DONE]') {
this.loading = false;
return;
};
const data = JSON.parse(msg.data);
console.log(data)
const finish_reason = data.choices[0].finish_reason;
const finish = finish_reason === 'stop' || finish_reason === 'length';
const content = data.choices[0].delta.content;
if (finish) {
this.loading = false;
} else if (content) {
......@@ -111,6 +111,7 @@ export default {
dialog.text += text;
}
},
// 连接发生错误
onerror: (err) => {
console.log("error", err);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册