This commit is contained in:
weipengfei 2024-01-17 10:21:43 +08:00
parent 7c28740994
commit 75564a95f0
5 changed files with 73 additions and 32 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

@ -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,52 +387,82 @@ 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<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;