This commit is contained in:
parent
65218f1317
commit
6f1435cd63
|
@ -3,7 +3,6 @@ declare namespace Chat {
|
|||
interface Chat {
|
||||
dateTime: string
|
||||
text: string
|
||||
mp3: Array<any> | null
|
||||
inversion?: boolean
|
||||
error?: boolean
|
||||
loading?: boolean
|
||||
|
|
|
@ -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) => {
|
||||
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"
|
||||
|
|
Loading…
Reference in New Issue