This commit is contained in:
weipengfei 2023-10-13 14:07:40 +08:00
parent 65218f1317
commit 6f1435cd63
2 changed files with 19 additions and 16 deletions

View File

@ -3,7 +3,6 @@ declare namespace Chat {
interface Chat {
dateTime: string
text: string
mp3: Array<any> | null
inversion?: boolean
error?: boolean
loading?: boolean

View File

@ -57,12 +57,12 @@ user_channel.on('message', (data: any) => {
if (recordFalg.value == 0) {
RecordXunfei()
recordFalg.value = 1
nowStauts.value = 'record'
nowStatus.value = 'record'
}
else {
RecordXunfei()
recordFalg.value = 0
nowStauts.value = 'loding'
nowStatus.value = 'loding'
handleSubmit()
}
})
@ -71,12 +71,12 @@ const changeRecord = ()=>{
if (recordFalg.value == 0) {
RecordXunfei()
recordFalg.value = 1
nowStauts.value = 'record'
nowStatus.value = 'record'
}
else {
RecordXunfei()
recordFalg.value = 0
nowStauts.value = 'loding'
nowStatus.value = 'loding'
}
}
@ -108,7 +108,7 @@ const conversationList = computed(() =>
const prompt = ref<string>('')
const loading = ref<boolean>(false)
const inputRef = ref<Ref | null>(null)
const nowStauts = ref('input') // , input, loding, record
const nowStatus = ref('input') // , input, loding, record
// PromptStore
const promptStore = usePromptStore()
@ -147,11 +147,11 @@ async function onConversation() {
// WebSocket
socket.onclose = (event: any) => {
console.log('连接已关闭: ', event)
nowStauts.value = 'input'
nowStatus.value = 'input'
}
socket.onerror = (event: any) => {
console.log('连接出错: ', event)
nowStauts.value = 'input'
nowStatus.value = 'input'
}
if (loading.value)
@ -196,7 +196,6 @@ async function onConversation() {
try {
let lastText = ''
const mp3: any = []
console.log('发送消息', message)
const fetchChatAPIOnce = async () => {
@ -209,15 +208,15 @@ async function onConversation() {
},
],
}))
nowStauts.value = 'loding'
nowStatus.value = 'loding'
// WebSocket
socket.onmessage = (event: any) => {
const msg = JSON.parse(event.data)
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
mp3.push(msg.payload.choices.mp3)
const loading = true
updateChat(
+uuid,
@ -225,7 +224,6 @@ async function onConversation() {
{
dateTime: new Date().toLocaleString(),
text: lastText,
mp3,
inversion: false,
error: false,
loading,
@ -233,6 +231,13 @@ async function onConversation() {
requestOptions: { prompt: message, options: { ...options } },
},
)
//
if(msg.header.code!=0||(event.data&&msg.header.status==2)){
socket.close()
}
} catch (error) {
socket.close()
}
}
// await fetchChatAPIProcess<Chat.ConversationResponse>({
@ -624,8 +629,8 @@ const click = () => {
<template>
<div class="flex w-full h-full my-layout">
<indexBG v-if="!isMobile">
<recording v-if="nowStauts=='record'"></recording>
<loding v-else-if="nowStauts=='loding'"></loding>
<recording v-if="nowStatus=='record'"></recording>
<loding v-else-if="nowStatus=='loding'"></loding>
<inputing v-else></inputing>
</indexBG>
<div class="flex flex-col w-full h-full" :style="{'max-width': maxWeight + 'px'}">
@ -671,7 +676,6 @@ const click = () => {
:key="index"
:date-time="item.dateTime"
:text="item.text"
:mp3="item.mp3"
:inversion="item.inversion"
:error="item.error"
:loading="item.loading"