diff --git a/aiChat/mixins/chatMixins.js b/aiChat/mixins/chatMixins.js index ed75c3d..4303c94 100644 --- a/aiChat/mixins/chatMixins.js +++ b/aiChat/mixins/chatMixins.js @@ -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' }, diff --git a/aiChat/views/index.vue b/aiChat/views/index.vue index ba1ff95..52d8563 100644 --- a/aiChat/views/index.vue +++ b/aiChat/views/index.vue @@ -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() diff --git a/api/chat/index.js b/api/chat/index.js index 14f241b..67a89c2 100644 --- a/api/chat/index.js +++ b/api/chat/index.js @@ -8,6 +8,10 @@ export function getCompletions(params) { return request.get('/v1/chat/sse/completions', params, { login: true }) } +export function getCompletionsV2(params) { + return request.get('/v1/chat/sse/completions2', params, { login: true }) +} + export function deleteChatItemByConversationId(id) { return request.delete('/v1/chat/message/' + id, {}, { login: true }) }