Refactor(AI):支持短时间内多个会话

This commit is contained in:
lifizer
2025-04-23 17:34:19 +08:00
parent 58b716c0ec
commit 74b02ed292
3 changed files with 40 additions and 34 deletions
+36 -32
View File
@@ -1,6 +1,6 @@
import {
getSseConfigV1,
getCompletions,
getCompletionsV2,
deleteChatItemByConversationId
} from '@/api/chat/index'
import { VUE_APP_API_URL } from '@/config'
@@ -184,39 +184,43 @@ export const chatMixins = {
type: -2
})
_this.loading = true
_this.initWebSocket(() => {
_this.showCursor = false
getSseConfigV1({
'chatNumber': _this.chatNumber,
prompt
}).then(resConfig => {
const conversationId = resConfig.data.conversationId
_this.chatNumber = resConfig.data.chatNumber || ''
_this.chatMessageList[_this.chatMessageListLength - 1].showCursor = true
_this.chatMessageList[_this.chatMessageListLength - 1].conversationId = conversationId
getCompletions({
conversationId,
ws: true,
isNoNeedPublicErrorNotification: 1
}).then(sseRes => {
console.log(sseRes)
// _this.closeWsFn()
}).catch(err => {
console.log(err)
_this.chatMessageList[_this.chatMessageListLength - 1].isError = true
_this.chatMessageList[_this.chatMessageListLength - 1].content = _this.errorMsg
_this.chatMessageList[_this.chatMessageListLength - 1].nodes = _this.errorMsg
_this.closeWsFn()
getSseConfigV1({
'chatNumber': _this.chatNumber,
prompt
}).then(resConfig => {
const conversationId = resConfig.data.conversationId
_this.chatNumber = resConfig.data.chatNumber || ''
_this.chatMessageList[_this.chatMessageListLength - 1].showCursor = true
_this.chatMessageList[_this.chatMessageListLength - 1].conversationId = conversationId
if (conversationId) {
_this.initWebSocket(conversationId, () => {
getCompletionsV2({
conversationId,
ws: true,
isNoNeedPublicErrorNotification: 1
}).then(sseRes => {
console.log(sseRes)
// _this.closeWsFn()
}).catch(err => {
console.log(err)
_this.chatErrorSetContent()
})
})
}).catch(err => {
console.log(err)
_this.chatMessageList[_this.chatMessageListLength - 1].isError = true
_this.chatMessageList[_this.chatMessageListLength - 1].content = _this.errorMsg
_this.chatMessageList[_this.chatMessageListLength - 1].nodes = _this.errorMsg
_this.closeWsFn()
})
} else {
_this.chatErrorSetContent()
}
}).catch(err => {
console.log(err)
_this.chatErrorSetContent()
})
},
chatErrorSetContent() {
this.chatMessageList[this.chatMessageListLength - 1].isError = true
this.chatMessageList[this.chatMessageListLength - 1].content = this.errorMsg
this.chatMessageList[this.chatMessageListLength - 1].nodes = this.errorMsg
this.closeWsFn()
},
closeWsFn() {
this.loading = false
if (this.chatMessageListLength) {
@@ -231,11 +235,11 @@ export const chatMixins = {
this.scrollToBottomHandle()
})
},
initWebSocket(cb) {
initWebSocket(conversationId, cb) {
const _this = this
console.log('------------------创建连接')
uni.connectSocket({
url: VUE_APP_API_URL.replace('https', 'wss') + settings.sysPrefix + `v1/chat/websocket/${_this.userInfo.unionId}`,
url: VUE_APP_API_URL.replace('https', 'wss') + settings.sysPrefix + `v1/chat/websocket/${_this.userInfo.unionId}-${conversationId}`,
header: {
'content-type': 'application/json'
},
-2
View File
@@ -296,7 +296,6 @@ export default {
this.chatMessageList = []
},
clickBackHandle() {
console.log(1)
if (!this.chatNumber) {
if (getCurrentPages().length > 1) {
uni.navigateBack()
@@ -310,7 +309,6 @@ export default {
}
},
pageContainerBeforeleave() {
console.log(22222)
if (!this.chatNumber) {
if (getCurrentPages().length > 1) {
uni.navigateBack()