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 { interface Chat {
dateTime: string dateTime: string
text: string text: string
mp3: Array<any> | null
inversion?: boolean inversion?: boolean
error?: boolean error?: boolean
loading?: boolean loading?: boolean

View File

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