diff --git a/.env b/.env index 9a7a52f..c1f7533 100644 --- a/.env +++ b/.env @@ -1,7 +1,8 @@ # Glob API URL VITE_GLOB_API_URL=/api -VITE_APP_API_BASE_URL=http://127.0.0.1:3002/ +# VITE_APP_API_BASE_URL=http://127.0.0.1:3002/ +VITE_APP_API_BASE_URL=https://ceshi-1.lihaink.cn/ # Whether long replies are supported, which may result in higher API fees VITE_GLOB_OPEN_LONG_REPLY=false diff --git a/.env.product b/.env.product new file mode 100644 index 0000000..bf70025 --- /dev/null +++ b/.env.product @@ -0,0 +1,10 @@ +# Glob API URL +VITE_GLOB_API_URL=/api + +VITE_APP_API_BASE_URL= + +# Whether long replies are supported, which may result in higher API fees +VITE_GLOB_OPEN_LONG_REPLY=false + +# When you want to use PWA +VITE_GLOB_APP_PWA=false diff --git a/.vscode/settings.json b/.vscode/settings.json index 005a2a6..346eb38 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,7 +2,7 @@ "prettier.enable": false, "editor.formatOnSave": false, "editor.codeActionsOnSave": { - "source.fixAll.eslint": true + "source.fixAll.eslint": "explicit" }, "eslint.validate": [ "javascript", diff --git a/src/views/chat/index.vue b/src/views/chat/index.vue index 5c1bf35..a3f24c0 100644 --- a/src/views/chat/index.vue +++ b/src/views/chat/index.vue @@ -301,7 +301,7 @@ let socket: WebSocket async function onConversation() { const message = prompt.value - socket = new WebSocket('wss://chat.lihaink.cn/chat') + socket = new WebSocket('wss://chat.lihaink.cn/doc') const promise = () => { return new Promise((resolve, reject) => { @@ -387,53 +387,83 @@ async function onConversation() { console.log('发送消息', message) const fetchChatAPIOnce = async () => { - socket.send(JSON.stringify({ - tts: 1, - data: [ + // socket.send(JSON.stringify({ + // tts: 1, + // data: [ + // ...infoList, + // ], + // })) + socket.send(JSON.stringify([ ...infoList, - ], - })) + ])) nowStatus.value = 'loding' - // 监听WebSocket接收消息事件 - socket.onmessage = (event: any) => { - try { - const msg = JSON.parse(event.data) - // console.log(`收到消息: `, msg.payload.choices.text[0].content); - // console.log(`当前消息: `, dataSources.value[dataSources.value.length - 1].text); - lastText += msg.payload.choices.text[0].content - console.log('返回的tts:', msg.payload.choices.tts_text) - msg.payload.choices.tts_text != '' ? tts.push(msg.payload.choices.tts_text) : null - const loading = false - nowStart.value = false - updateChat( + // // 监听WebSocket接收消息事件 + // socket.onmessage = (event: any) => { + // try { + // const msg = JSON.parse(event.data) + // // console.log(`收到消息: `, msg.payload.choices.text[0].content); + // // console.log(`当前消息: `, dataSources.value[dataSources.value.length - 1].text); + // lastText += msg.payload.choices.text[0].content + // console.log('返回的tts:', msg.payload.choices.tts_text) + // msg.payload.choices.tts_text != '' ? tts.push(msg.payload.choices.tts_text) : null + // const loading = false + // nowStart.value = false + // updateChat( + // +uuid, + // dataSources.value.length - 1, + // { + // dateTime: new Date().toLocaleString(), + // text: lastText, + // inversion: false, + // tts: JSON.stringify(tts), + // error: false, + // loading, + // conversationOptions: { conversationId: msg.header.sid, parentMessageId: msg.header.sid }, + // requestOptions: { prompt: message, options: { ...options } }, + // }, + // ) + // scrollToBottomIfAtBottom() + // // 关闭连接 + // if (msg.header.code != 0 || (event.data && msg.header.status == 2)) { + // nowStatus.value = 'input' + // socket.close() + // } + // } + // catch (error) { + // console.log(error) + // nowStatus.value = 'input' + // socket.close() + // } + // } + + socket.onmessage = (event: any)=>{ + console.log(event.data); + lastText+=event.data; + const loading = false; + nowStart.value = false; + if(!event.data.includes('[finish]')) updateChat( +uuid, dataSources.value.length - 1, { dateTime: new Date().toLocaleString(), text: lastText, inversion: false, - tts: JSON.stringify(tts), + tts: JSON.stringify(+uuid), error: false, loading, - conversationOptions: { conversationId: msg.header.sid, parentMessageId: msg.header.sid }, + conversationOptions: { conversationId: uuid, parentMessageId: uuid }, requestOptions: { prompt: message, options: { ...options } }, }, ) - scrollToBottomIfAtBottom() + else{ // 关闭连接 - if (msg.header.code != 0 || (event.data && msg.header.status == 2)) { nowStatus.value = 'input' socket.close() } - } - catch (error) { - console.log(error) - nowStatus.value = 'input' - socket.close() - } - } + scrollToBottomIfAtBottom() + } // await fetchChatAPIProcess({ // prompt: message, diff --git a/src/websocket/socket.ts b/src/websocket/socket.ts index 1948ae8..b22d584 100644 --- a/src/websocket/socket.ts +++ b/src/websocket/socket.ts @@ -1,4 +1,4 @@ -const socket = new WebSocket('wss://chat.lihaink.cn/chat') +const socket = new WebSocket('wss://chat.lihaink.cn/doc') export default socket;