From dfebec03af4c1e1187a1bd05e9b87de0ea5c9bb1 Mon Sep 17 00:00:00 2001 From: 6448dfb631ba9538b4877fd6 <6448dfb631ba9538b4877fd6@devide> Date: Tue, 30 May 2023 01:39:03 +0000 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0fetchEventSource=E9=87=8C?= =?UTF-8?q?=E9=9D=A2=E7=9A=84=E5=9B=9E=E8=B0=83=E5=87=BD=E6=95=B0=E7=9A=84?= =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/App.vue b/src/App.vue index bfa09f0..cdaa727 100644 --- a/src/App.vue +++ b/src/App.vue @@ -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); } -- GitLab