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 # Glob API URL
VITE_GLOB_API_URL=/api 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 # Whether long replies are supported, which may result in higher API fees
VITE_GLOB_OPEN_LONG_REPLY=false 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, "prettier.enable": false,
"editor.formatOnSave": false, "editor.formatOnSave": false,
"editor.codeActionsOnSave": { "editor.codeActionsOnSave": {
"source.fixAll.eslint": true "source.fixAll.eslint": "explicit"
}, },
"eslint.validate": [ "eslint.validate": [
"javascript", "javascript",

View File

@ -301,7 +301,7 @@ let socket: WebSocket
async function onConversation() { async function onConversation() {
const message = prompt.value const message = prompt.value
socket = new WebSocket('wss://chat.lihaink.cn/chat') socket = new WebSocket('wss://chat.lihaink.cn/doc')
const promise = () => { const promise = () => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -387,53 +387,83 @@ async function onConversation() {
console.log('发送消息', message) console.log('发送消息', message)
const fetchChatAPIOnce = async () => { const fetchChatAPIOnce = async () => {
socket.send(JSON.stringify({ // socket.send(JSON.stringify({
tts: 1, // tts: 1,
data: [ // data: [
// ...infoList,
// ],
// }))
socket.send(JSON.stringify([
...infoList, ...infoList,
], ]))
}))
nowStatus.value = 'loding' nowStatus.value = 'loding'
// WebSocket // // WebSocket
socket.onmessage = (event: any) => { // socket.onmessage = (event: any) => {
try { // try {
const msg = JSON.parse(event.data) // const msg = JSON.parse(event.data)
// console.log(`: `, msg.payload.choices.text[0].content); // // console.log(`: `, msg.payload.choices.text[0].content);
// console.log(`: `, dataSources.value[dataSources.value.length - 1].text); // // console.log(`: `, dataSources.value[dataSources.value.length - 1].text);
lastText += msg.payload.choices.text[0].content // lastText += msg.payload.choices.text[0].content
console.log('返回的tts:', msg.payload.choices.tts_text) // console.log('tts:', msg.payload.choices.tts_text)
msg.payload.choices.tts_text != '' ? tts.push(msg.payload.choices.tts_text) : null // msg.payload.choices.tts_text != '' ? tts.push(msg.payload.choices.tts_text) : null
const loading = false // const loading = false
nowStart.value = false // nowStart.value = false
updateChat( // 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, +uuid,
dataSources.value.length - 1, dataSources.value.length - 1,
{ {
dateTime: new Date().toLocaleString(), dateTime: new Date().toLocaleString(),
text: lastText, text: lastText,
inversion: false, inversion: false,
tts: JSON.stringify(tts), tts: JSON.stringify(+uuid),
error: false, error: false,
loading, loading,
conversationOptions: { conversationId: msg.header.sid, parentMessageId: msg.header.sid }, conversationOptions: { conversationId: uuid, parentMessageId: uuid },
requestOptions: { prompt: message, options: { ...options } }, requestOptions: { prompt: message, options: { ...options } },
}, },
) )
scrollToBottomIfAtBottom() else{
// //
if (msg.header.code != 0 || (event.data && msg.header.status == 2)) {
nowStatus.value = 'input' nowStatus.value = 'input'
socket.close() socket.close()
} }
} scrollToBottomIfAtBottom()
catch (error) { }
console.log(error)
nowStatus.value = 'input'
socket.close()
}
}
// await fetchChatAPIProcess<Chat.ConversationResponse>({ // await fetchChatAPIProcess<Chat.ConversationResponse>({
// prompt: message, // prompt: message,

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; export default socket;