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

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