Compare commits

...

3 Commits

Author SHA1 Message Date
shengchanzhe 1e33b69be7 更新 2024-02-04 14:48:36 +08:00
weipengfei 8f979f5478 更新 2024-01-17 18:12:00 +08:00
weipengfei 75564a95f0 更新 2024-01-17 10:21:43 +08:00
7 changed files with 111 additions and 34 deletions

3
.env
View File

@ -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

10
.env.product Normal file
View File

@ -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

View File

@ -2,7 +2,7 @@
"prettier.enable": false,
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"eslint.validate": [
"javascript",

View File

@ -152,6 +152,8 @@ async function loadTTS() {
//
const watchTTS = watch(() => props.tts, async (n: any, o: any) => {
console.log('文本变化', n);
if (props.tts == '') {
for (let i = 0; i < audioElements.length; i++) {
audioElements[i].pause()

View File

@ -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) => {
@ -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,
}
})
@ -387,26 +387,74 @@ async function onConversation() {
console.log('发送消息', message)
const fetchChatAPIOnce = async () => {
socket.send(JSON.stringify({
tts: 1,
data: [
...infoList,
],
}))
// socket.send(JSON.stringify({
// tts: 1,
// data: [
// ...infoList,
// ],
// }))
socket.send(JSON.stringify([
...infoList,
]))
console.log('发送中', 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
// // 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 = (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,
@ -417,22 +465,33 @@ async function onConversation() {
tts: JSON.stringify(tts),
error: false,
loading,
conversationOptions: { conversationId: msg.header.sid, parentMessageId: msg.header.sid },
conversationOptions: { conversationId: uuid, parentMessageId: uuid },
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)
else if (event.data.tts_text) {
updateChat(
+uuid,
dataSources.value.length - 1,
{
dateTime: new Date().toLocaleString(),
text: lastText,
inversion: false,
tts: JSON.stringify(tts),
error: false,
loading,
conversationOptions: { conversationId: uuid, parentMessageId: uuid },
requestOptions: { prompt: message, options: { ...options } },
},
)
}
else {
//
nowStatus.value = 'input'
socket.close()
}
scrollToBottomIfAtBottom()
}
// await fetchChatAPIProcess<Chat.ConversationResponse>({

View File

@ -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;

View File

@ -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"