diff --git a/src/views/chat/index.vue b/src/views/chat/index.vue index 130e454..64a4a66 100644 --- a/src/views/chat/index.vue +++ b/src/views/chat/index.vue @@ -361,7 +361,7 @@ async function onConversation() { infoList = infoList.map((item: any, index: any) => { return { - role: item.role, + role: item.role || 'assistant', content: item.text, } }) @@ -393,9 +393,11 @@ async function onConversation() { // ...infoList, // ], // })) - socket.send(JSON.stringify([ - ...infoList, - ])) + socket.send(JSON.stringify([ + ...infoList, + ])) + + console.log('发送中', infoList) nowStatus.value = 'loding' @@ -438,22 +440,22 @@ async function onConversation() { // } // } - socket.onmessage = (e: any)=>{ - console.log(e.data); - let event = { - data: { - event: '', - text: '', - tts_text: '' - } - }; - event.data = JSON.parse(e.data); - const loading = false; - nowStart.value = false; - event.data.tts_text != '' ? tts.push(event.data.tts_text) : null - if(!event.data.event.includes('finish')) { - lastText+=event.data.text; - updateChat( + socket.onmessage = (e: any) => { + console.log(e.data) + const event = { + data: { + event: '', + text: '', + tts_text: '', + }, + } + event.data = JSON.parse(e.data) + const loading = false + nowStart.value = false + event.data.tts_text != '' ? tts.push(event.data.tts_text) : null + if (!event.data.event.includes('finish')) { + lastText += event.data.text + updateChat( +uuid, dataSources.value.length - 1, { @@ -467,8 +469,9 @@ async function onConversation() { requestOptions: { prompt: message, options: { ...options } }, }, ) - } else if(event.data.tts_text){ - updateChat( + } + else if (event.data.tts_text) { + updateChat( +uuid, dataSources.value.length - 1, { @@ -482,13 +485,14 @@ async function onConversation() { requestOptions: { prompt: message, options: { ...options } }, }, ) - } else{ + } + else { // 关闭连接 - nowStatus.value = 'input' - socket.close() - } - scrollToBottomIfAtBottom() - } + nowStatus.value = 'input' + socket.close() + } + scrollToBottomIfAtBottom() + } // await fetchChatAPIProcess({ // prompt: message, diff --git a/yarn.lock b/yarn.lock index 6e9841b..18291dd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1162,10 +1162,10 @@ resolved "https://registry.npmjs.org/@emotion/hash/-/hash-0.8.0.tgz" integrity sha512-kBJtf7PH6aWwZ6fka3zQ0p6SBYzx4fl1LoZXE2RrnYST9Xljm7WfKJrU4g/Xr3Beg72MLrp1AWNUmuYJTL7Cow== -"@esbuild/win32-x64@0.17.18": +"@esbuild/darwin-x64@0.17.18": version "0.17.18" - resolved "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.17.18.tgz" - integrity sha512-qU25Ma1I3NqTSHJUOKi9sAH1/Mzuvlke0ioMJRthLXKm7JiSKVwFghlGbDLOO2sARECGhja4xYfRAZNPAkooYg== + resolved "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.17.18.tgz" + integrity sha512-Qq84ykvLvya3dO49wVC9FFCNUfSrQJLbxhoQk/TE1r6MjHo3sFF2tlJCwMjhkBVq3/ahUisj7+EpRSz0/+8+9A== "@eslint-community/eslint-utils@^4.1.2", "@eslint-community/eslint-utils@^4.2.0", "@eslint-community/eslint-utils@^4.3.0": version "4.4.0" @@ -3273,6 +3273,11 @@ fs.realpath@^1.0.0: resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz" integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw== +fsevents@~2.3.2: + version "2.3.2" + resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz" + integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA== + function-bind@^1.1.1: version "1.1.1" resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz"